As code for my project is evolving, new indexes are being put in place and I am sure some old ones are no longer necessary. However before I just drop them to see if anything slows down or not, I’d prefer if there is a more programmatic or analytic way to determine if an index is being used any more.
I don’t see anything in the system.indexes collection, but ideally there is some stats on index accesses somewhere! Is this the case?
Run your
db.collection.find(...)queries with.explain()tacked onto the end. That is the single most useful way to see how queries are running: http://www.mongodb.org/display/DOCS/ExplainYou can also turn on profiling, and the profile log entries give you index usage for each query profiled. There aren’t any aggregate stats, as of yet, though. In particular, it won’t give you which indexes aren’t being used, only the index that is being used (for each query). (Edit: I must have been imagining that–you have to get the query from the profiler and then run explain on it. Kind of painful manually.) http://www.mongodb.org/display/DOCS/Database+Profiler
Update:
Just saw this from mongolab; looks like an interesting new project along these lines: http://blog.mongolab.com/2012/06/introducing-dex-the-index-bot/
Update:
I created a script to check for indexes that aren’t used, via the profiler:
https://github.com/wfreeman/indexalizer