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

getlasterror.n documentation is misleading

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: mongodb-2.6, mongodb-3.0
    • Component/s: Server
    • Labels:
      None
    • Last comment by Customer:
      true
    • Sprint:
      Docs Sprint Current (511)

      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

              Assignee:
              kay.kim Kay Kim (Inactive)
              Reporter:
              jeff.yemin Jeffrey Yemin
              Participants:
              Last commenter:
              Jonathan Dahl Jonathan Dahl
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since reply:
                6 years, 17 weeks, 2 days ago
                Date of 1st Reply: