w3resource

MongoDB: db.getLastErrorObj() method

db.getLastErrorObj

The db.getLastErrorObj() method is used to return the status document for the last operation.

Syntax:

db.getLastErrorObj()

Parameters:

Name Description Required /
Optional
Type
key The write concern’s w value. Optional int or string
wtimeout The time limit in milliseconds. Optional int

Example: MongoDB: db.getLastError() method

The following example will return a document provides error information on the previous write operation.

db.getLastErrorObj(2);

Output:

> db.getLastErrorObj(2);
2016-01-13T13:19:47.370+0530 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
} at src/mongo/shell/db.js:533

Retrieve the restaurants data from here

Previous: db.getLastError() method
Next: db.getMongo() method



Follow us on Facebook and Twitter for latest update.