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

multi-update in the presence of an error gives incorrect nModified / nMatched value

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.8
    • Component/s: Write Ops
    • None
    • Query
    • ALL
    • Hide
      db.test.drop()
      db.test.ensureIndex({num:1},{unique:true})
      db.test.insert([{num:0},{num:2},{num:4},{num:6},{num:7},{num:10}])
      db.test.update({},{$inc:{num:1}},{multi:true})
      

      Gives:

      WriteResult({
              "nMatched" : 0,
              "nUpserted" : 0,
              "nModified" : 0,
              "writeError" : {
                      "code" : 11000,
                      "errmsg" : "E11000 duplicate key error collection: mt.test index: num_1 dup key: { : 7.0 }"
              }
      })
      

      But...

      > db.test.find({},{_id:0})
      { "num" : 1 }
      { "num" : 3 }
      { "num" : 5 }
      { "num" : 6 }
      { "num" : 7 }
      { "num" : 10 }
      

      3 documents were modified. We would expect "nMatched" and "nModified" to be at least 3.

      Show
      db.test.drop() db.test.ensureIndex({num:1},{unique:true}) db.test.insert([{num:0},{num:2},{num:4},{num:6},{num:7},{num:10}]) db.test.update({},{$inc:{num:1}},{multi:true}) Gives: WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0, "writeError" : { "code" : 11000, "errmsg" : "E11000 duplicate key error collection: mt.test index: num_1 dup key: { : 7.0 }" } }) But... > db.test.find({},{_id:0}) { "num" : 1 } { "num" : 3 } { "num" : 5 } { "num" : 6 } { "num" : 7 } { "num" : 10 } 3 documents were modified. We would expect "nMatched" and "nModified" to be at least 3.

      If a multi:true update is run such that it fails halfway the resulting nModified / nMatched fields appear to always be set to zero (and the appropriate error given) even if documents have been modified.

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            andrew.ryder@mongodb.com Andrew Ryder (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: