In this post, we'll show you how to find unused indexes in MongoDB, check usage statistics on your index collection, and drop your unused indexes.

Actively managing MongoDB database indexes over several application releases can be challenging for development teams. Requirements often change with every release, where several new indexes may be added and old indexes might become abandoned. Over time, this makes it difficult to keep track of which MongoDB indexes are being used and which ones are now unnecessary.

Indexes have a big impact on write performance — every time there's a write to a collection, the relevant indexes need to be updated. A lack of indexes manifests immediately and slows down the query — unused indexes are more subtle and need to be actively pruned out to improve write performance. More information can be found here.

In earlier versions of MongoDB, there was no easy way to determine if an index was not being used. However, starting in version 3.2, MongoDB added support for the $indexStats operator, which lets you gather statistics about your index usage.

Finding Unused Indexes in MongoDB

To check usage statistics of a particular index on a collection, you can use this command: