[SERVER-17301] Subcollection update does not work. Created: 17/Feb/15  Updated: 17/Feb/15  Resolved: 17/Feb/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Benjamin Harel Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File dump.tgz    
Issue Links:
Duplicate
duplicates SERVER-14837 Positional Operator matching wrong ne... Closed
Operating System: ALL
Steps To Reproduce:

$ mongo ran_q_test
 
> db.users.update({"_id":ObjectId("54a251b862656e1dc1000000"),"contacts._id":ObjectId("54a251b862656e1dc1010000"),"contacts.0.contact_ranks._id": ObjectId("54a251b862656e1dc1030000")}, {"$set": {"contacts.0.contact_ranks.$.value": 200000}})

You will expect that contact_rank document with the id: 54a251b862656e1dc1030000 will have updated attribute "value", n'est ce pas?
But somehow you discover that the other document was updated with the id 54a251b862656e1dc1020000
My conclusion is that it updates the first element in sub collection.

> db.users.find()[0].contacts[0].contact_ranks
[
	{
		"_id" : ObjectId("54a251b862656e1dc1020000"),
		"_type" : "ContactRank",
		"name" : "sexy",
		"value" : 200000
	},
	{
		"_id" : ObjectId("54a251b862656e1dc1030000"),
		"_type" : "ContactRank",
		"name" : "cool"
	},
	{
		"_id" : ObjectId("54a251b862656e1dc1040000"),
		"_type" : "ContactRank",
		"name" : "hot"
	},
	{
		"_id" : ObjectId("54a251b862656e1dc1050000"),
		"_type" : "ContactRank",
		"name" : "smart"
	},
	{
		"_id" : ObjectId("54a251b862656e1dc1060000"),
		"_type" : "ContactRank",
		"name" : "ugly"
	},
	{
		"_id" : ObjectId("54a251b862656e1dc1070000"),
		"_type" : "ContactRank",
		"name" : "angry"
	}
]

Participants:

 Description   

Subcollection in third level updates only the first element and not the correct one. Please open the dump and run the attached queries. I've reported this bug for version 2.6.3 but I still have it in amazon mongodb official product
https://aws.amazon.com/marketplace/pp/B00COAAEH8/ref=sp_mpg_product_title?ie=UTF8&sr=0-2
that uses 2.6.5

And I want a ticket to MongoDB world !!!!



 Comments   
Comment by Ramon Fernandez Marina [ 17/Feb/15 ]

bharel, the positional $ operator cannot be used in queries that traverse more than one array. See the documentation for more details.

I'm resolving this ticket as a duplicate of SERVER-14837. You may also be interested in reading SERVER-14662, which is open to evaluate improvements in this area.

Regards,
Ramón.

Generated at Thu Feb 08 03:43:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.