Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shukla2112/f26e531774cdd79dc8181274ccaca3d1 to your computer and use it in GitHub Desktop.
Save shukla2112/f26e531774cdd79dc8181274ccaca3d1 to your computer and use it in GitHub Desktop.
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
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