Skip to content

Instantly share code, notes, and snippets.

@arohter
Forked from joeyAghion/mongodb_collection_sizes.js
Last active August 29, 2015 14:06
Show Gist options
  • Save arohter/5be5d84b70892c361365 to your computer and use it in GitHub Desktop.
Save arohter/5be5d84b70892c361365 to your computer and use it in GitHub Desktop.
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(
stats[c]['ns'] + ": " +
"total_size=" + Math.floor(stats[c]['size']/1048576) + " mb, " +
"idx_size=" + Math.floor(stats[c]['totalIndexSize']/1048576) + " mb, " +
"allocated=" + Math.floor(stats[c]['storageSize']/1048576) + " mb, " +
"num_docs=" + stats[c]['count']
);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment