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

XMLWordPrintableJSON

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

      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:
              Scott Hernandez (Inactive)
              Reporter:
              Olga Ignatova
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: