MongoDB: db.getLastError() method
db.getLastError
The db.getLastError() method is used to check and return the status of the last operation.
Syntax:
db.getLastError(>w>, >wtimeout>)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
w | 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 display the error information on the previous write operation.
db.getLastError(2);
Output:
> db.getLastError(2); 2016-01-13T13:09:04.997+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.getCollectionNames() method
Next:
db.getLastErrorObj() 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