In MongoDB, you can get an explanation for how a query was executed, with interesting performance information:
> db.people.find({ 'items' : { '$gte' : 1 } }).explain()
Can I get the same for a "count" (which is not a query, but a command)?
> db.people.count({ 'items' : { '$gte' : 1 } })
The explain command provides information on the execution of the following commands: aggregate , count , distinct , find , findAndModify , delete , mapReduce , and update .
Description. n = count( conn , collection ) returns the total number of documents in a collection by using the MongoDB connection. n = count( conn , collection ,'Query', mongoquery ) returns the total number of documents in an executed MongoDB query on a collection.
The Atlas Search count option adds a field to the metadata results document that displays a count of the search results for the query. You can use count to determine the size of the result set. You can use it in the $search or $searchMeta stage.
Mongo 3.0 introduced a new way of explaining non-cursor requests:
db.my_collection.explain().count()
See: http://docs.mongodb.org/manual/reference/method/db.collection.explain/#db.collection.explain
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With