0

I am trying to get the index usage statistics in a mongoDB 2.0.9.

I found a similar question in https://stackoverflow.com/questions/44813787/how-to-check-index-usage-in-mongodb but this only applies to versions 3.2 and up.

Any assistance will be very appreciated.

0

The $indexstats command was added for the MongoDB 3.2 server release in Dec 2015. Without server support for measuring or logging index use, I'm not aware of any obvious workaround short of modifying the 2.0.x server code and building a custom server.

MongoDB 2.0 is a relatively ancient server version: it was first released in Sept 2011 and reached End-of-Life in March 2013. I'd strongly recommend planning to upgrade to a modern & supported version of MongoDB (currently 3.4+, although 3.4 will reach EOL in Jan 2020). There are numerous essential bug fixes, stability, and security improvements since 2.0.

  • Thanks you @Stennie, we are looking into upgrading for a while and hopefully will get it done soon. – Eran Mor Aug 12 at 18:32
0

You can run the below js against the database you want and it would print the list of indexes that 0 access:

db.getCollectionNames().forEach(function(collection){
    db.getCollection(collection).aggregate([{
        $indexStats: {}
        }, {
            $match: {
                "accesses.ops": NumberLong(0)
                }
        }]).forEach(function(doc) {
            print("Index Key:" + JSON.stringify(doc.key) + "in collection" + "has" + doc.accesses.ops + "accesses");
            });
});

Hope this helps your need until you upgrade your cluster!

Thank you!

-Anban

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.