Skip to content

Instantly share code, notes, and snippets.

@karan9
Last active November 5, 2020 10:15
Show Gist options
  • Save karan9/bbf172e48b3651fb9b0fae62a5421e63 to your computer and use it in GitHub Desktop.
Save karan9/bbf172e48b3651fb9b0fae62a5421e63 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: { } } ] );
var len = indexes.length
ret.push({ "name": coll, "length": len, "data": stats._batch});
})
printjson(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment