[SERVER-206] $set cannot update an embedded object and create an embedded object at the same time Created: 31/Jul/09  Updated: 12/Jul/16  Resolved: 14/Jan/10

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 0.9.7
Fix Version/s: 1.3.1

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

Participants:

 Description   

I found this bug (I think):

// create an object with an embedded set of objects
db.example.insert({_id:1,set:[

{key1:'v1'}

]});

// now updated key1 in set and add an embedded object
// the relevant objects are separate from each other so it should work
db.example.update({_id:1}, { $set : { 'set.0.key1' : 'v2', 'new.key' : 'bla' }});

// however it doesn't
db.getPrevError()
"

{"err" : "Modifier spec implies existence of an encapsulating object with a name that already represents a non-object, or is referenced in another $set clause" , "n" : 0 , "nPrev" : 1 , "ok" : 1}

"

// doing the updates separate from each other does work:
> db.example.update({_id:1},{$set: { 'set.0.key1' : 'v3' }});
> db.example.update({_id:1},{$set: { 'new.key' : 2 }});
> db.example.find()
{"_id" : 1 , "set" : [

{"key1" : "v3"}

] , "new" : {"key" : 2}}

I guess, somehow it is not possible to use $set to create a new embedded object while at the same time updating an existing embedded object.



 Comments   
Comment by auto [ 14/Jan/10 ]

Author:

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

Message: test for SERVER-206
http://github.com/mongodb/mongo/commit/a40772067168bd7a905a1b4f170e734d5bdd4a23

Comment by Wouter [ 31/Jul/09 ]

Hmm maybe it is related to this bug:

http://jira.mongodb.org/browse/SERVER-181

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