Does MongoDB track how many times each index is used in a query? Does MongoDB track how many times each index is used in a query? mongodb mongodb

Does MongoDB track how many times each index is used in a query?


You can use $indexStats (new in version 3.2):

db.collection.aggregate([{ $indexStats: { } }])

Which, besides other information, returns the number of operations that used the index (ops property).

{    "name" : "_id_",    "key" : { "_id" : 1 },    "host" : "test-dev:27017",    "accesses" : {        "ops" : NumberLong(2),        "since" : ISODate("2016-04-21T14:15:57.846Z")     } }