Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6124

$unset may create a nested field if it doesn't exist

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.5
    • Affects Version/s: 2.0.3, 2.1.2
    • Component/s: Write Ops
    • ALL

      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}
      

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            oignatova Olga Ignatova
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: