It seems that in some situations an update with $unset operator may create nested fields. It only seems to happen if at least one of the fields of the $unset operator matches an existing field in the document.
E.g.
> db.test.save({a:1}) > db.test.find() {"_id" : ObjectId("..."), "a" : 1} > db.test.update({}, {$unset:{"a":1, "b.c":1}}, false, true) > db.test.find() {"_id" : ObjectId("..."), "b" : {}}
The field "b.c" didn't exist in the original document and an empty object "b" got created as a result of the update.
Note, that this only happens when at least one of the fields used by the $unset operator exists in the document. If I modify the update() operation as follows, no insertion happens:
> db.test.update({}, {$unset:{"b.c":1}}, false, true) > db.test.find() {"_id" : ObjectId("..."), "a" : 1}
- related to
-
SERVER-6047 $pullAll causes empty embedded object field to be created
- Closed