I have a mongodb replica set with a lot of databases, collections & indexes.
We did a lot of refactor and optimization and, of course, I have a lot of \"creative
The simplest solution to this is to use the mongodb inbuilt $indexStats
Using the Mongo console run -
db.collection.aggregate([ { $indexStats: { } } ])
Using PyMongo -
from pymongo import MongoClient
collection = MongoClient()[db_name][collection_name]
index_stats = collection.aggregate([{'$indexStats':{}}])
for index_info in index_stats:
print index_info
Apologies for re-opening an old question. This shows up on the first page of google searches and the only answer is to use a snippet of unmaintained code.