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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 3.2.8
    • None
    • Write Ops
    • None
    • 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.

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: