[DOCS-2197] Comment on: "manual/reference/operator/update/positional.txt" Created: 06/Nov/13  Updated: 03/Nov/17  Resolved: 06/Nov/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Improvement Priority: Major - P3
Reporter: auto Assignee: Unassigned
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

osx 10.9, mongodb 2.4.6

Location: http://docs.mongodb.org/manual/reference/operator/update/positional/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36
Referrer: http://docs.mongodb.org/manual/reference/operator/update-array/
Screen Resolution: 1920 x 1200
repo: docs
source: reference/operator/update/positional


Participants:
Days since reply: 10 years, 15 weeks ago

 Description   

Hi. Let use next doc for example:

db.test.save({
    _id: 1,
    categories: [
        {parent_id: 1001, _id: 1, name: 'one'},
        {parent_id: 1001, _id: 2, name: 'two'},
        {parent_id: 1001, _id: 3, name: 'three'},
    ]
})

When i'm doing:

db.test.update({_id: 1, 'categories._id': 2, 'categories.parent_id': 1001}, {$set: {'categories.$.name': 'two - UPDATED'}})

expecting to see second sub-document's name change. However, this query will update first sub-doc:

db.test.find({_id: 1}).pretty()
{
	"_id" : 1,
	"categories" : [
		{
			"_id" : 1,
			"name" : "two - UPDATED",
			"parent_id" : 1001
		},
		{
			"parent_id" : 1001,
			"_id" : 2,
			"name" : "two"
		},
		{
			"parent_id" : 1001,
			"_id" : 3,
			"name" : "three"
		}
	]
}

To get expected results I'll have to move 'categories._id' parameter in query to the end:

db.test.update({_id: 1, 'categories.parent_id': 1001, 'categories._id': 2}, {$set: {'categories.$.name': 'two - UPDATED'}})



 Comments   
Comment by Kay Kim (Inactive) [ 06/Nov/13 ]

sent email to user to clarify his query condition

Generated at Thu Feb 08 07:42:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.