常用JavaScript語句
復(fù)制代碼 代碼如下:
db.getSiblingDB(dbname>)
db.getCollectionNames()
db.getCollection(collname>)
db.printCollectionStats()
在mongo shell運行JavaScript腳本
切換數(shù)據(jù)庫:
復(fù)制代碼 代碼如下:
use dbname>
運行如下腳本:
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下運行
復(fù)制代碼 代碼如下:
mongo localhost:27017/dbname> dbaStatCollections.js
或在mongo shell下運行
復(fù)制代碼 代碼如下:
load("dbaStatCollections.js")
在服務(wù)端存儲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ù)。退出該會話后,該函數(shù)不會被保存。只可在Primary執(zhí)行。
備注:以上輸出結(jié)果保存為CSV文件打開。
本文出自 “SQL Server Deep Dives” 博客
您可能感興趣的文章:- mongoDB中CRUD的深入講解
- Mongo DB增刪改查命令
- mongodb+php實現(xiàn)簡單的增刪改查
- MongoDB.NET 2.2.4驅(qū)動版本對Mongodb3.3數(shù)據(jù)庫中GridFS增刪改查
- PHP簡單操作MongoDB的方法(安裝及增刪改查)
- mongodb增刪改查詳解_動力節(jié)點Java學(xué)院整理
- MongoDB簡單操作示例【連接、增刪改查等】
- koa+mongoose實現(xiàn)簡單增刪改查接口的示例代碼
- Node.js對MongoDB進行增刪改查操作的實例代碼
- java連接Mongodb實現(xiàn)增刪改查
- MongoDB的基本操作實例詳解【服務(wù)端啟動,客戶端連接,CRUD操作】