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
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join