3 Star 7 Fork 10

mo-shan / script

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
mongo.js 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
moshan 提交于 2019-07-17 16:02 . add mongo.js
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]);
}
1
https://gitee.com/mo-shan/script.git
git@gitee.com:mo-shan/script.git
mo-shan
script
script
master

搜索帮助