[SERVER-18639] Expose number of modified documents in getLastError output Created: 23/May/15  Updated: 27/May/15  Resolved: 27/May/15

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Ramon Fernandez Marina Assignee: Unassigned
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-3409 WriteResult should indicate number of... Closed
Related
related to DOCS-5491 getlasterror.n documentation is misle... Closed
Participants:

 Description   

This came up in DOCS-5491: getLastError.n represents the number of matched documents, but it doesn't return the number of modified documents. 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
}

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

Can the number of modified documents be added to the output of getLastError?



 Comments   
Comment by Ramon Fernandez Marina [ 27/May/15 ]

mitar, insert operations in 2.6 use a new write protocol, and return a WriteResult() object containing the results of the operation – this is the object you want to examine to get the information you need.

This new write protocol eliminates the need to call getLastError, and while calling GLE is permitted for backwards compatibility reasons it does not contain information only available in this new write protocol.

Regards,
Ramón.

Generated at Thu Feb 08 03:48:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.