MongoDB update: how to check if an update succeeds or fails?
How do you know what rows are affected with a MongoDB update?
As with all write operations, getLastError
command in MongoDB can confirm the result of the update's write operation, described here:
http://docs.mongodb.org/manual/applications/update/
The getLastError
command returns the error status of the last operation on the current connection. By default MongoDB does not provide a response to confirm the success or failure of a write operation, clients typically use getLastError in combination with write operations to ensure that the write succeeds.
http://docs.mongodb.org/manual/reference/command/getLastError/#getLastError