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

WriteResult should indicate number of docs modified (no-ops excluded)

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.5
    • Affects Version/s: 1.8.2
    • Component/s: Write Ops
    • Labels:
    • Fully Compatible
    • 0

      Report both the number of documents ("n") which were matched and have the expected updated values, and the number of docs which were actually changed with a write to the database ("nDocsModified").

      Expected:

      > db.rb.save({_id:3, a:[1,2]})
      Updated 1 existing record(s) in 6ms
      Update WriteResult({ "ok" : 1, "nDocsModified" : 1, "n" : 1 ... })
      
      // No-op doesn't require modifying the document
      > db.rb.save({_id:3, a:[1,2]})
      Updated 1 existing record(s) in 2ms
      Update WriteResult({ "ok" : 1, "nDocsModified" : 0, "n" : 1 ... })
      

      Note: These changes only apply to the new write commands, not the old wire protocol updates. This means you must be using a new driver/client to see this field in the WriteResults.

      Old Description
      db.foo.save(

      {a: 1, n: [ 'foo' ] }

      )
      db.foo.update(

      {a: 1}

      , {$addToSet:

      { n: 'foo' }

      } )

      db.getPrevError();

      { "err" : null, "updatedExisting" : true, "n" : 1, "nPrev" : 1, "ok" : 1 }

      updatedExisting should be false in this case, since the document was not, in fact, updated.

            Assignee:
            scotthernandez Scott Hernandez (Inactive)
            Reporter:
            kbanker Kyle Banker
            Votes:
            17 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: