db.getLastErrorObj()
Definition
db.
getLastErrorObj
()- Specifies the level of write concern for confirming the successof previous write operation issued over the same connection andreturns the document for that operation.
When using db.getLastErrorObj()
, clients must issue thedb.getLastErrorObj()
on the same connection as the writeoperation they wish to confirm.
The db.getLastErrorObj()
is a mongo
shellwrapper around the getLastError
command.
Changed in version 2.6: A new protocol for write operations integrates write concerns with thewrite operations, eliminating the need for a separate db.getLastErrorObj()
.Most write methods now returnthe status of the write operation, including error information.In previous versions, clients typically used the db.getLastErrorObj()
incombination with a write operation to verify that the writesucceeded.
The db.getLastErrorObj()
can accept the followingparameters:
ParameterTypeDescriptionkey
int or stringOptional. The write concern’s w
value.wtimeout
intOptional. The time limit in milliseconds.
Behavior
The returned document provides error information on theprevious write operation.
If the db.getLastErrorObj()
method itself encounters an error, such as anincorrect write concern value, the db.getLastErrorObj()
throws an exception.
For information on the returned document, see getLastErrorcommand.
Example
The following example issues a db.getLastErrorObj()
operationthat verifies that the preceding write operation, issued over the sameconnection, has propagated to at least two members of the replica set.
- db.getLastErrorObj(2)
See also