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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Minor - P4 Minor - P4
    • None
    • 3.4.10
    • Querying
    • Query
    • ALL

    Description

      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 })
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: