- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get execution stats in MongoDB for a collection
To get stats, use explain() in MongoDB. Let us create a collection with documents −
> db.demo157.insertOne({"Status":"Active"}); { "acknowledged" : true, "insertedId" : ObjectId("5e354fdffdf09dd6d08539fc") } > db.demo157.insertOne({"Status":"InActive"}); { "acknowledged" : true, "insertedId" : ObjectId("5e354fe3fdf09dd6d08539fd") }
Display all documents from a collection with the help of find() method −
> db.demo157.find();
This will produce the following output −
{ "_id" : ObjectId("5e354fdffdf09dd6d08539fc"), "Status" : "Active" } { "_id" : ObjectId("5e354fe3fdf09dd6d08539fd"), "Status" : "InActive" }
Following is how to implement explain() in MongoDB −
> db.demo157.find({Status: { $in: ['Active','InActive'] }}).explain("executionStats");
This will produce the following output −
{ "queryPlanner" : { "plannerVersion" : 1, "namespace" : "test.demo157", "indexFilterSet" : false, "parsedQuery" : { "Status" : { "$in" : [ "Active", "InActive" ] } }, "winningPlan" : { "stage" : "COLLSCAN", "filter" : { "Status" : { "$in" : [ "Active", "InActive" ] } }, "direction" : "forward" }, "rejectedPlans" : [ ] }, "executionStats" : { "executionSuccess" : true, "nReturned" : 2, "executionTimeMillis" : 18, "totalKeysExamined" : 0, "totalDocsExamined" : 2, "executionStages" : { "stage" : "COLLSCAN", "filter" : { "Status" : { "$in" : [ "Active", "InActive" ] } }, "nReturned" : 2, "executionTimeMillisEstimate" : 0, "works" : 4, "advanced" : 2, "needTime" : 1, "needYield" : 0, "saveState" : 0, "restoreState" : 0, "isEOF" : 1, "invalidates" : 0, "direction" : "forward", "docsExamined" : 2 } }, "serverInfo" : { "host" : "DESKTOP-QN2RB3H", "port" : 27017, "version" : "4.0.5", "gitVersion" "3739429dd92b92d1b0ab120911a23d50bf03c412" }, "ok" : 1 }
- Related Articles
- How to gather extended query execution stats in Oracle?
- Get all fields names in a MongoDB collection?
- Get the maximum element in MongoDB collection?
- How to get array from a MongoDB collection?
- Get the size of a collection in MongoDB using conditions?
- Looping MongoDB collection for sorting
- Updating MongoDB collection for _id?
- Get the top most document from a MongoDB collection
- Get MongoDB documents with max attribute per group in a collection?
- Get all embedded documents with “isMarried” status in a MongoDB collection
- Get names of all keys in the MongoDB collection?
- How to get unique values from MongoDB collection?
- Get the count of the number of documents in a MongoDB Collection?
- Get the maximum mark records from a collection with documents in MongoDB
- Clone a collection in MongoDB?

Advertisements