mongodb集合大小

mongodb统计集合大小 

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 = [];
c
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
s
stats = stats.sort(function(a, b) { return b['count'] - a['count']; });

for (var c in stats) { print(stats[c]['ns'] + " , " + stats[c]['count'] + " ," + getReadableFileSizeString(stats[c]['storageSize']) + ""); }

输出结果

xxxx.unit_customer_mapping , 44749602 ,4.1 GB
xxxx.skmr_msg_info , 37206942 ,10.0 GB
xxxx.skmr_action_logs_history , 27015390 ,7.8 GB
xxxx.daily_unit_stat , 20550193 ,1.0 GB
xxxx.chat_messages , 11815168 ,2.1 GB
xxxx.conversation_messages , 11016384 ,1.3 GB
xxxx.skmr_unit_to_house_log , 10327816 ,992.9 MB
xxxx.tencent_chat_messages , 9646876 ,1.6 GB
xxxx.skmr_action_logs , 8675658 ,3.5 GB

 

你可能感兴趣的:(Mongodb)