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

Update $push with empty $each reports nModified = 1 on MongoDB 3.4

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.4.10
    • Component/s: Querying
    • Labels:
    • Query
    • ALL

      An update operation with an empty $push and an empty $each on an empty array gets reported as nModified = 1 on MongoDB 3.4, even though no documents have been modified.

      The command result on 3.6 seems to be more correct.

      There's no difference between the behavior of the command on 3.6 and previous versions.

      > db.test.find()
      { "_id" : ObjectId("59fc96b0721d164cc5a90500"), "x" : [ ] }
      
      // 3.4
      > db.test.update({},{$push:{x:{$each:[]}}})
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
      
      // 3.6
      > db.test.update({},{$push:{x:{$each:[]}}})
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
      

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            robert.guo@mongodb.com Robert Guo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: