Index Responsibly
Indexes and Usages
Below is an example of showing indexes and their usages of collection mdb.numbers from a 2-shard sharded cluster. Keyhole highlights redundant indexes in red with a leading ‘x’ and unused indexes since the mongo server started in blue with a leading ‘?’. A shard key is with a leading ‘*’ character. Usually, redundant indexes are those that can be covered by another compound index. On the other hand, before dropping any unused indexes, check with the development teams on the purpose of creating those in the first place. See example outputs below:
You can drag the output file to Maobi to create an HTML report. Maobi produces a nicer presentation than viewing all index info in a terminal window.
Mirror Indexes to Another Cluster
Another useful feature is to duplicate all indexes from a MongoDB cluster to another. The command with -index option outputs a file with a -index.bson.gz suffix. By reading the output file and with a destination cluster’s connection string, Keyhole, with the -createIndex option, duplicates indexes to the destination cluster. For example:.
keyhole --createIndex shard2-0.local-index.bson.gz \
"mongodb+srv://user:xxxxxx@hostname.mongodb.net/"
Find Words
The information of indexes and their usages are also collected by Keyhole with the -allinfo option. Checkout the Survey Your Mongo Land for details.
Comments