Created
February 29, 2016 19:19
-
-
Save vladzloteanu/f91b47c99d3c28853f6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getReadableFileSizeString(fileSizeInBytes) { | |
var i = -1; | |
var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; | |
do { | |
fileSizeInBytes = fileSizeInBytes / 1024; | |
i++; | |
} while (fileSizeInBytes > 1024); | |
return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; | |
}; | |
var collectionNames = db.getCollectionNames(), stats = []; | |
collectionNames.forEach(function (n) { stats.push(db.getCollection(n).stats()); }); | |
function sortCollectionsBy(key) { | |
print("Sorting by " + key); | |
print("==================") | |
stats = stats.sort(function(a, b) { return b[key] - a[key]; }); | |
for (var c in stats) { print(stats[c]['ns'] + ": " + getReadableFileSizeString(stats[c][key])); } | |
} | |
sortCollectionsBy('size'); | |
sortCollectionsBy('storageSize'); | |
sortCollectionsBy('totalIndexSize'); | |
sortCollectionsBy('count'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment