Details
-
Improvement
-
Status: Closed
-
Minor - P4
-
Resolution: Fixed
-
None
-
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
- is related to
-
SERVER-17999 Regression between MongoDB 2.4 and 2.6
-
- Closed
-
-
SERVER-18639 Expose number of modified documents in getLastError output
-
- Closed
-
- related to
-
DOCS-5287 getlasterror page clarify
-
- Closed
-