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

getlasterror.n documentation is misleading

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • None
    • mongodb-2.6, mongodb-3.0
    • Server
    • None
    • Docs Sprint Current (511)
    • true

    Description

      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
      }
      

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                7 years, 1 week, 2 days ago