[DOCS-5491] getlasterror.n documentation is misleading Created: 22/May/15  Updated: 02/Nov/16  Resolved: 26/May/15

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: mongodb-2.6, mongodb-3.0

Type: Improvement Priority: Minor - P4
Reporter: Jeffrey Yemin Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DOCS-5287 getlasterror page clarify Closed
is related to SERVER-17999 Regression between MongoDB 2.4 and 2.6 Closed
is related to SERVER-18639 Expose number of modified documents i... Closed
Participants:
Days since reply: 8 years, 38 weeks, 1 day ago

 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
}



 Comments   
Comment by Githook User [ 26/May/15 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-5287 DOCS-5491 getLastError return fields
Branch: master
https://github.com/mongodb/docs/commit/a7f62c51dad401eda4b060b756be673597fd6e18

Comment by Githook User [ 26/May/15 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-5287 DOCS-5491 getLastError return fields
Branch: v2.6
https://github.com/mongodb/docs/commit/e7da3903717a391e8197e323a6d930868211e9ec

Comment by Ramon Fernandez Marina [ 23/May/15 ]

mitar, I've opened SERVER-18639 to request that getLastError returns the number of updated documents.

Comment by NOVALUE Mitar [ 22/May/15 ]

But could `getlasterror` also return the number of really updated documents? That number is available, why it would not be available in the `getlasterror`?

Comment by Jeffrey Yemin [ 22/May/15 ]

Note that "n" also applies to findandmodify.

Generated at Thu Feb 08 07:50:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.