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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 1.8.2
    • Fix Version/s: 2.5.5
    • Component/s: Write Ops
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Linked BF Score:
      0

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Votes:
              17 Vote for this issue
              Watchers:
              15 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: