MongoDB服務(wù)端JavaScript腳本

MongoDB服務(wù)端JavaScript腳本

創(chuàng)新互聯(lián)致力于成都網(wǎng)站制作、成都做網(wǎng)站,成都網(wǎng)站設(shè)計(jì),集團(tuán)網(wǎng)站建設(shè)等服務(wù)標(biāo)準(zhǔn)化,推過標(biāo)準(zhǔn)化降低中小企業(yè)的建站的成本,并持續(xù)提升建站的定制化服務(wù)水平進(jìn)行質(zhì)量交付,讓企業(yè)網(wǎng)站從市場競爭中脫穎而出。 選擇創(chuàng)新互聯(lián),就選擇了安全、穩(wěn)定、美觀的網(wǎng)站建設(shè)服務(wù)!

 

常用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ù)。退出該會話后,該函數(shù)不會被保存。只可在Primary執(zhí)行。

備注:以上輸出結(jié)果保存為CSV文件打開。

在mongo shell啟動(dòng)配置文件.mongorc.js中存儲JavaScript函數(shù)

mongodb shell默認(rèn)會加載~/.mongorc.js文件,可以自定義prompt變量來修改shell提示信息。也可以將上述常用的DBA管理函數(shù)放到這里。

分享標(biāo)題:MongoDB服務(wù)端JavaScript腳本
分享網(wǎng)址:http://muchs.cn/article10/ghijdo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、搜索引擎優(yōu)化、軟件開發(fā)App開發(fā)、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(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)

成都定制網(wǎng)站建設(shè)