Created
September 26, 2017 08:12
-
-
Save swateek/f3fb5ebd7473ff8a8da0fe39ad5fa8b8 to your computer and use it in GitHub Desktop.
collection_size_to_csv.js
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']; }); | |
print("collection,size,sizeOnDisk"); | |
for(var c in stats){ | |
print(stats[c]['ns'] + "," + stats[c]['size'] + "," + stats[c]['storageSize']); // in bytes | |
//print(stats[c]['ns'] + "," + stats[c]['size']/1000000 + "," + stats[c]['storageSize']/1000000); // in MBs | |
//print(stats[c]['ns'] + "," + stats[c]['size']/1000000000 + "," + stats[c]['storageSize']/1000000000); // in GBs | |
} | |
// How to use: | |
// cat collection_size_to_csv.js | mongo > output.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment