常用JavaScript語(yǔ)句
運(yùn)行如下腳本:
var total = 0;var dbaStatCollections = function(){}; dbaStatCollections = function(){ collNames = db.getCollectionNames(); for (var index = 0; index < collNames.length; index++) { var coll = db.getCollection(collNames[index]); var stats = coll.stats(); print('ns,count,size,totalIndexSize'); print(stats.ns + ',' + stats.count + ',' + stats.size + ',' + stats.totalIndexSize); }} dbaStatCollections();
可將上述腳本保存為dbaStatCollections.js,
在linux shell下運(yùn)行
或在mongo shell下運(yùn)行
在服務(wù)端存儲(chǔ)JavaScript函數(shù)
db.system.js.remove({"_id":"dbaStatCollections"}); db.system.js.save( { _id : "dbaStatCollections" , value : function () { collNames = db.getCollectionNames(); for (var index = 0; index < collNames.length; index++) { var coll = db.getCollection(collNames[index]); var stats = coll.stats(); print('ns,count,size,totalIndexSize'); print(stats.ns + ',' + stats.count + ',' + stats.size + ',' + stats.totalIndexSize); } }}); db.loadServerScripts(); dbaStatCollections();
在當(dāng)前JavaScript上下文中,可以使用該函數(shù)。退出該會(huì)話后,該函數(shù)不會(huì)被保存。只可在Primary執(zhí)行。
備注:以上輸出結(jié)果保存為CSV文件打開(kāi)。
本文出自 “SQL Server Deep Dives” 博客
新聞熱點(diǎn)
疑難解答
圖片精選