Shell MongoDB: check if update is done

Similarly Upgrading MongoDB: How to check if upgrade succeeded or failed? but for the default mongodb shell. db.collection.update () will execute silently in both cases: when the query found the document and when not. And getLastError is also null after both updates.

How can I tell if something has actually been updated without re-requesting the collection?

I am using MongoDB version 2.0.4

onUbuntu 12.04

+3


source to share


1 answer


db.getLastErrorObj()

is what you want to call to get the update result. It returns an object that looks like this:

{
    "updatedExisting" : true,
    "n" : 2,
    "connectionId" : 35,
    "err" : null,
    "ok" : 1
}

      



n

- the number of updated documents.

+5


source







All Articles