getLastError(w?, wtimeout?)
This method specifies the level of write concern for confirming the success of a previous write operation issued over the same connection and returns the error string for that operation.
Note:
When using db.getLastError(), clients must issue the db.getLastError() on the same connection as the write operation they wish to confirm.
Syntax:
db.getLastError(w)
where w is any number.
Example 1: When the last error success.
MongoDB
db.getLastError(1)
Output:
null
Example 2: When lasterror failed
MongoDB
db.getLastError(2)
Output:
uncaught exception: Error: getlasterror failed: {"connectionId" : 1,"n" : 0,"badGLE" : {"getlasterror" : 1,"w" : 2},"ok" : 0,"errmsg" : "cannot use 'w' > 1 when a host is not replicated","code" : 2,"codeName" : "BadValue"} :_getErrorWithCode@src/mongo/shell/utils.js:25:13DB.prototype.getLastErrorObj@src/mongo/shell/db.js:706:15DB.prototype.getLastError@src/mongo/shell/db.js:689:15
No comments:
Post a Comment