How to get an explain for a MongoDB count?

mongodb

Solution

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

Problem

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 } }) ```

Original source