db.getLastErrorObj(), clients must issue the
db.getLastErrorObj()on the same connection as the write operation they wish to confirm.
Changed in version 2.6: A new protocol for write operations integrates write concerns with the write operations, eliminating the need for a separate
db.getLastErrorObj(). Most write methods now return the status of the write operation, including error information. In previous versions, clients typically used the
db.getLastErrorObj()in combination with a write operation to verify that the write succeeded.
db.getLastErrorObj()can accept the following parameters:
Parameter Type Description
int or string Optional. The write concern’s
int Optional. The time limit in milliseconds.
The returned document provides error information on the previous write operation.
db.getLastErrorObj() method itself encounters an error, such as an
incorrect write concern value, the
db.getLastErrorObj() throws an exception.
For information on the returned document, see getLastError command.