mongodbHow to use "explain" in MongoDB?
MongoDB's explain()
method is used to provide information about how MongoDB executes a query. It can be used to analyze query performance and identify potential areas of improvement.
Example
db.collection.explain("executionStats")
Output example
{
"queryPlanner" : {
...
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 1,
"executionTimeMillis" : 0,
"totalKeysExamined" : 0,
"totalDocsExamined" : 0,
"executionStages" : {
...
},
"allPlansExecution" : [ ]
},
"serverInfo" : {
...
},
"ok" : 1
}
The output of explain()
contains the following information:
queryPlanner
: The query plan MongoDB used to execute the query.executionStats
: Statistics about the query execution, such as the number of documents examined and the execution time.serverInfo
: Information about the server on which the query was executed.
Helpful links
More of Mongodb
- How to check the version of MongoDB?
- How to use watch in MongoDB?
- How to update one document in MongoDB?
- How to update many documents in MongoDB?
- How to use MongoDB queue?
- How to create a many to many relation in MongoDB?
- How to insert new document into MongoDB?
- How to use hint in MongoDB?
- How to work with time series data in MongoDB?
- How to use unwind in MongoDB?
See more codes...