Skip to content

Instantly share code, notes, and snippets.

@Alphadelta14
Created April 23, 2014 05:57
Show Gist options
  • Save Alphadelta14/11204129 to your computer and use it in GitHub Desktop.
Save Alphadelta14/11204129 to your computer and use it in GitHub Desktop.
// `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