[SERVER-181] $set with array indexes Created: 23/Jul/09  Updated: 12/Jul/16  Resolved: 18/Dec/09

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: 1.3.0

Type: Improvement Priority: Minor - P4
Reporter: Eliot Horowitz (Inactive) Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 6
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-333 mixing $inc and $push Closed
Participants:

 Description   

[fcoury@imac 17:47]:$ mongo
MongoDB shell version: 0.9.6
url: test
connecting to: test
type "help" for help
> db.sample.remove();
> db.sample.save({"_id" : "db1940364a68bbca000000a1" , "test" : [

{"name" : "domain" , "default" : "" , "validation" : "" , "validation_error" : "" , "label" : "Domain" , "required" : false}

]})
> db.sample.update(

{"_id":"db1940364a68bbca000000a1"}

, {$set: {"test.0.new_attribute": "new_value"}})
> db.sample.find();
{"_id" : "db1940364a68bbca000000a1" , "test" : [

{"name" : "domain" , "default" : "" , "validation" : "" , "validation_error" : "" , "label" : "Domain" , "required" : false}

]}



 Comments   
Comment by auto [ 28/Dec/09 ]

Author:

{'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: more tests for SERVER-181
http://github.com/mongodb/mongo/commit/95137f262c2a57831dccf058428a2f64e900496e

Comment by auto [ 18/Dec/09 ]

Author:

{'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: tests and minor fixes for SERVER-181 and SERVER-273
http://github.com/mongodb/mongo/commit/da08edb63dc7ba51a236608f9288b4bef969db1a

Comment by Eliot Horowitz (Inactive) [ 16/Oct/09 ]

I created the following document (notebook):
notebook = {
"code" : "456",
"notes" : [

{ "id" : 4, "name" : "Graphics Note", "tags" : [ "graphics", "coding", "maths" ], }

,

{ "id" : 5, "name" : "Food Note", "tags" : [ "pizza", "coke", "movie" ], }

,
]
}

Notebook contains a list of collections (called notes). Now, after
lots of googling I read that a field of an individual note, in this
case, should be updated as follows:
db["notebooks"].update(

{ "code":"456", "notes.id":4 }

,

{ "$set" : { "notes.0.id" : 3 }

}, safe=True);

But, if I try to do this:
db["notebooks"].update(

{ "code":"456", "notes.id":4 }

,

{ "$set" : { "notes.0.name" : "Cool Graphics Note" }

}, safe=True);
it fails with this message: "Modifier spec implies existence of an
encapsulating object with a name that already represents a non-object,
or is referenced in another $set clause"

Generated at Thu Feb 08 02:53:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.