Skip to content

Instantly share code, notes, and snippets.

@alexbevi
Created March 6, 2020 21:06
Show Gist options
  • Save alexbevi/9066fe14a41dc1b69aefa5ef3edac8c9 to your computer and use it in GitHub Desktop.
Save alexbevi/9066fe14a41dc1b69aefa5ef3edac8c9 to your computer and use it in GitHub Desktop.
// Print index details
print(["Namespace", "Index Name", "Index Size", "Index Keys", "Usage Count", "Last Used"].join('\t'));
db.getMongo().getDBNames().forEach(function (dbname) {
db.getSiblingDB(dbname).getCollectionNames().forEach(function (cname) {
var coll = db.getSiblingDB(dbname).getCollection(cname);
var stats = coll.stats();
coll.aggregate([ { $indexStats: {} } ]).forEach(function(ix) {
var ixname = ix.name;
var ns = dbname + "." + cname;
var ixsize = stats.indexSizes[ixname];
var ops = ix.accesses.ops;
var since = ix.accesses.since;
print([ns, ixname, ixsize, JSON.stringify(ix.key), ops, since].join('\t'));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment