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

Expose number of modified documents in getLastError output

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • Labels:
      None

      This came up in DOCS-5491: getLastError.n represents the number of matched documents, but it doesn't return the number of modified documents. For example:

      > db.foo.insert({x:1, y:2})
      WriteResult({ "nInserted" : 1 })
      > db.foo.update({x:1}, {$set: {y:2}})
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
      > db.runCommand( { getLastError: 1, w: 1 } )
      {
              "connectionId" : 22,
              "updatedExisting" : true,
              "n" : 1,
              "syncMillis" : 0,
              "writtenTo" : null,
              "err" : null,
              "ok" : 1
      }
      
      > db.foo.update({x:3}, {$set:{y:3}}, {upsert:true})
      WriteResult({
              "nMatched" : 0,
              "nUpserted" : 1,
              "nModified" : 0,
              "_id" : ObjectId("555f835e3bd3ad1bd7a14b9f")
      })
      > db.runCommand( { getLastError: 1, w: 1 } )
      {
              "connectionId" : 22,
              "n" : 0,
              "syncMillis" : 0,
              "writtenTo" : null,
              "err" : null,
              "ok" : 1
      }
      

      Can the number of modified documents be added to the output of getLastError?

            Assignee:
            Unassigned Unassigned
            Reporter:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: