Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// `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
You can’t perform that action at this time.