Skip to content

Instantly share code, notes, and snippets.

@petermd
Created July 13, 2017 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petermd/427fce0e07ad9ead02a74d576508b6fe to your computer and use it in GitHub Desktop.
Save petermd/427fce0e07ad9ead02a74d576508b6fe to your computer and use it in GitHub Desktop.
Get database collections and size sorted in descending order
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']/(1024*1024) + ")"); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment