Created
September 25, 2017 16:44
-
-
Save swateek/d374a0c2abc0c0cfebc9f19ab0118c10 to your computer and use it in GitHub Desktop.
Use to calculate sizes of MongoDB collections.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use <dbname>; | |
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'] + " bytes (" + stats[c]['storageSize'] + " bytes)"); // in bytes | |
//print(stats[c]['ns'] + ": " + stats[c]['size']/1000000 + " MB (" + stats[c]['storageSize']/1000000 + " MB)"); // in MBs | |
//print(stats[c]['ns'] + ": " + stats[c]['size']/1000000000 + " GB (" + stats[c]['storageSize']/1000000000 + " GB)"); // in GBs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment