Pregunta

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.

¿Fue útil?

Solución

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
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top