WiredTiger Index File – How to Match to Corresponding Collection

mongo-repairmongodb

I have a mongodb database with about 2 billion records, shared between 20 or so collections. Each of these collections has an index on it, based on a single key (other than _id).

I have an index file (named index-1-5374774422504609475.wt) that I'd like to match to a collection. Is there a quick way to match directly which index file corresponds to a collection?

I do mean the actual physical index file in the mongo db directory.

Thanks in advance!

Best Answer

Ref: https://docs.mongodb.com/manual/reference/method/db.collection.stats/

https://docs.mongodb.com/manual/reference/command/collStats/#collStats.indexDetails

As you are using WiredTiger storage engine you can use db.collection.stats() with indexDetails option set to true.

Easy copy paste:

.stats({"indexDetails":true})

A document that reports data from the WiredTiger storage engine for each index in the collection. Other storage engines will return an empty document.

The fields in this document are the names of the indexes, while the values themselves are documents that contain statistics for the index provided by the storage engine. These statistics are for internal diagnostic use.