常用JavaScript語句
運行如下腳本:
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下運行
或在mongo shell下運行
在服務端存儲JavaScript函數
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();
在當前JavaScript上下文中,可以使用該函數。退出該會話后,該函數不會被保存。只可在Primary執行。
備注:以上輸出結果保存為CSV文件打開。
本文出自 “SQL Server Deep Dives” 博客
|
新聞熱點
疑難解答