Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-5491

getlasterror.n documentation is misleading

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • mongodb-2.6, mongodb-3.0
    • Affects Version/s: None
    • Component/s: Server
    • Labels:
      None

      The documentation for getlasterror.n is not entirely accurate. It states:

      n reports the number of documents updated or removed, if the preceding operation was an update or remove operation.

      It should say something like:

      n reports the number of documents matched by the query to an update or a remove, if the preceding operation was an update or remove operation. For a remove, the number matched will equal the number removed. But for an update, the number matched may be smaller than the number actually modified.

      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
      }
      

      and for an upsert:

      > 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
      }
      

            Assignee:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              8 years, 51 weeks, 5 days ago