How To Find Unused Indexes In MongoDB | MongoDB Index
loader image
MongoDB Web Development

How To Find Unused Indexes In MongoDB

Reason Why We should Remove The Unused Indexes In MongoDB First:

Handling MongoDB indexes over other application releases can be really challenging plot for the developers. On most of the case, the requirement for each release will get change so several new indexes will be included and old indexes may wind up. When the time passes by, it will be too hard for the developers to monitor which MongoDB Indexes are being utilized and which are not being utilized as of now.

If the relevant indexes are not updated, then the query will be slowly processed and as the result, the unused indexes will also become slow in responding to the queries. These need to be actively trimmed out to improve the database performance.

Indexes are doing a major role to increase the database performance. Whenever the changes occur in the collection then immediately the important indexes should be updated base on that DB performance increasing.

Therefore here am planning to explain the solutions to find out an unused index in MongoDB, and how to check usage statistics on the indexed collection, and how to drop indexes from the indexed collection.

In earlier versions of MongoDB, there was no such feature to identify whether an index was in an unused state or not. However, in version 3.2 MongoDB introduced a new feature to identify the unused indexes and added support for the “$indexStats” operator. Here, I am using MongoDB $indexStats to identify and remove unused indexes.

Finding Out Unused Indexes In MongoDB:

Step 1: To check for usage statistic of a particular index on a collection based on index name


Step 2: To get the statistics for all the indexes of a collection:





Note: Here, you have to note the two important fields:

   i) Ops:

This resembles the number of operations which had used the index.

   ii) Since:

This resembles the time from which MongoDB had started gathering stats, and its typically will be the last start time.

Related: Which Is Best? Aggregation or Map Reduce | MongoDb


How To Drop Unused Indexes In MongoDB:

Once the unused MongoDB indexes are identified and verified, you can drop the index using the given code:

Step 1: We can drop the unused index using the index name.


Step 2:  We can drop the unused index using the index key.


Before using these commands, please verify whether the index you are about to drop is the right index or not.

Also Read: MongoDB Sharding Setup on Ubuntu 14.04

Finding out unused indexes is a regular task that every DB should do. Maintaining a proper indexing system is a critical part of a database performance. A single unindexed query is enough to down the total performance of an application so it is always mandatory to remove the unused indexes from MongoDB. 

Was it helpful? Read more from us here

Want to craft websites using MEAN STACK?  Hire Highly trained MEAN STACK developers possesses who can efficiently transform your ideas into effective business.

The following two tabs change content below.


Senior Full Stack Developer having 3 years of experience in Web development arena , Expertise in MEAN stack, Python, Javascript, Angular. And, This freaking humor bomb loves to involve himself in playing auspicious Games but Once you reach him, he ll always make sure to light up your terrific days with laughter's.

Leave a Reply

Your email address will not be published. Required fields are marked *