代码拉取完成,页面将自动刷新
var length_list=[30, 20 , 20]; //默认集合名最大长度是30, 文档数的最大长度是20位, 大小的数字的最大长度是20位,如果超过该值,请加大,否则显示格式会错乱哦
var sort = 3; //排序字段,可选1 2 3,1表示以第一列(集合名),2表示第二列(集合的文档个数),3表示第三列(集合的大小)
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 = [];
collectionNames.forEach(function(n) {
stats.push(db[n].stats());
});
var stats = stats.sort(function(a, b) {
if (sort == 1) {
return b['ns'] - a['ns'];
} else if (sort == 2) {
return b['count'] - a['count'];
} else {
return b['storageSize'] - a['storageSize'];
}
});
for (var c in stats){
var str = [stats[c]['ns'], stats[c]['count']+"", getReadableFileSizeString(stats[c]['storageSize'])];
var table = ["1", "1", "1"];
for (var index = 0; index < str.length; index++){
var length_tmp = length_list[index] - str[index].length;
for (var l = 0; l < length_tmp; l++) {
str[index] = str[index] + " ";
}
table[index] = str[index];
}
print(table[0] + table[1] + table[2]);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。