Created
April 23, 2014 05:57
-
-
Save Alphadelta14/11204129 to your computer and use it in GitHub Desktop.
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
// `mongo 127.0.0.1/MMApp collections.js` | |
function size(size) { | |
var unit, res, factor=1; | |
['B', 'KB', 'MB', 'GB', 'TB'].every(function(unit_) { | |
factor_ = factor*1024; | |
res = size/factor_; | |
unit = unit_; | |
if(isNaN(res) || res < 1) { | |
return false; | |
} | |
factor = factor_; | |
return true; | |
}); | |
return [Math.sigFig(size/factor, 3), unit].join(' '); | |
} | |
var totalSize = 0, | |
totalDisk = 0; | |
db.getCollectionNames() | |
.forEach(function(collection){ | |
var stats = db[collection].stats(); | |
totalSize += stats.size; | |
totalDisk += stats.storageSize; | |
print('Name:', collection); | |
print('Records:', stats.count); | |
print('Size:', size(stats.size)); | |
print('Disk:', size(stats.storageSize)); | |
}) | |
print('\nTotals:') | |
print('Size:', size(totalSize)); | |
print('Disk:', size(totalDisk)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment