Using the mongo shell what needs to added to an update/delete query to also return the number of rows that were affected by the query.
Asked
Active
Viewed 3,548 times
1 Answers
7
I don't think there is a way to get that number directly from the call, but you can call the following right afterwards:
db.runCommand({getLastError: 1})
This will return a json object. the "n" key in that object will tell you the number of documents affected:
{
"updatedExisting" : true,
"n" : 1,
"connectionId" : 26,
"err" : null,
"ok" : 1
}

Jaime Morales
- 369
- 1
- 4
-
2Just add write concern to the call and it will automatically poll a get last error and reutrn the response – Sammaye Aug 06 '13 at 23:20
-
Thanks @Sammaye. That seems like the best solution – Jaime Morales Aug 06 '13 at 23:35