Skip to content

Instantly share code, notes, and snippets.

@kylemclaren
Forked from joeyAghion/mongodb_collection_sizes.js
Last active November 25, 2021 11:41
Show Gist options
  • Save kylemclaren/fbb8c585f8047ee69e9b to your computer and use it in GitHub Desktop.
Save kylemclaren/fbb8c585f8047ee69e9b 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'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment