I found this bug (I think):
// create an object with an embedded set of objects
db.example.insert({_id:1,set:[
]});
// 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()
"
"
// 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" : [
] , "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.