Skip to content

Instantly share code, notes, and snippets.

@danyanya
Last active January 24, 2023 07:54
Show Gist options
  • Save danyanya/a420a5de87d80f7039b208c24d9ce532 to your computer and use it in GitHub Desktop.
Save danyanya/a420a5de87d80f7039b208c24d9ce532 to your computer and use it in GitHub Desktop.
# One line JS code to check MongoDB collection storageSize
var collectionNames = db.getCollectionNames(), stats = []; collectionNames.forEach(function (n) { stats.push(db.getCollection(n).stats()); }); stats = stats.sort(function(a, b) { return b['storageSize'] - a['storageSize']; }); 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