Created
March 6, 2020 21:06
-
-
Save alexbevi/9066fe14a41dc1b69aefa5ef3edac8c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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