本篇文章給大家分享的是有關(guān)MongoDB服務(wù)端中怎么使用JavaScript腳本,小編覺得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

常用JavaScript語句
db.getSiblingDB(<dbname>)
db.getCollectionNames()
db.getCollection(<collname>)
db.printCollectionStats()
在mongo shell運(yùn)行JavaScript腳本
切換數(shù)據(jù)庫:
use <dbname>
運(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 localhost:27017/<dbname> dbaStatCollections.js
或在mongo shell下運(yùn)行
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ù)。退出該會(huì)話后,該函數(shù)不會(huì)被保存。只可在Primary執(zhí)行。
以上就是MongoDB服務(wù)端中怎么使用JavaScript腳本,小編相信有部分知識點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見到或用到的。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道。
分享標(biāo)題:MongoDB服務(wù)端中怎么使用JavaScript腳本-創(chuàng)新互聯(lián)
URL分享:http://www.chinadenli.net/article8/djddip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、Google、外貿(mào)網(wǎng)站建設(shè)、搜索引擎優(yōu)化、網(wǎng)站排名、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容