Skip to content

Instantly share code, notes, and snippets.

@karan9
Last active December 9, 2020 19:12
Show Gist options
  • Save karan9/7abe7eda52cddedacaa2ff3fa73c0750 to your computer and use it in GitHub Desktop.
Save karan9/7abe7eda52cddedacaa2ff3fa73c0750 to your computer and use it in GitHub Desktop.
var colls = db.getCollectionNames();
var ret = [];
colls.forEach(function(coll) {
if (String(coll).startsWith("system")) {
return;
}
var indexes = db.getCollection(coll).getIndexes();
var stats = db.getCollection(coll).aggregate( [ { $indexStats: { } } ] ).toArray();
var len = indexes.length
ret.push({ "name": coll, "length": len, "data": stats});
})
printjson(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment