Created
February 24, 2015 11:29
-
-
Save alexzaporozhets/09d83ef80023c2464bc3 to your computer and use it in GitHub Desktop.
Mongdb collections ordered by size
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
function bytesToSize(bytes) { | |
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; | |
if (bytes == 0) return '0 Byte'; | |
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); | |
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i]; | |
}; | |
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'] + ": " + bytesToSize(stats[c]['size']) + " (" + bytesToSize(stats[c]['storageSize']) + ")"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment