共計(jì) 1466 個(gè)字符,預(yù)計(jì)需要花費(fèi) 4 分鐘才能閱讀完成。
自動寫代碼機(jī)器人,免費(fèi)開通
MongoDB1.9.1 中有哪些定制化功能,相信很多沒有經(jīng)驗(yàn)的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
MongoDB1.9.1 有哪些定制化的功能
簡單的字符串定義
myReplSetName:SECONDARY prompt=
//ah,bliss
//somesysadminsthink isaweirdprompt,asit salso
//usedforredirections,sotheymightprefer$
prompt= $
$
$//therewego
函數(shù)式定義
prompt=function(){returndb+}
test usefoo
foo usebar
bar
更復(fù)雜的函數(shù)
states=[STARTUP , PRIMARY , SECONDARY , RECOVERING , FATAL ,
… STARTUP2 , UNKNOWN , ARBITER , DOWN , ROLLBACK ]
prompt=function(){
…result=db.isMaster();
…if(result.ismaster){
…returndb+
…}
…elseif(result.secondary){
…return (+db+)
…}
…result=db.adminCommand({replSetGetStatus:1})
…returnstates[result.myState]+ : +db+
…}
(test)
MongoDB1.9.1 有哪些定制化的功能
告訴你是否連接的是 mongos 機(jī)器
prompt=function(){
…result=db.adminCommand({isdbgrid:1});
…if(result.ok==1){
…return mongos
…}
…return
…}
告訴你當(dāng)前的時(shí)間
prompt=function(){
…varnow=newDate();
…returnnow.getHours()+ : +now.getMinutes()+ : +now.getSeconds()+
…}
10:30:45 db.foo.count()
60000
10:30:46
還可以定義在配置文件里
$#loadfromcommandlinearg:
$mongoshellConfig.js
MongoDBshellversion1.9.1-
connectingto:test
//loadfromtheshellitself
load(/path/to/my/shellConfig.js)
另一個(gè)新功能是自動加載的配置文件,類似于.bashrc,這個(gè)文件會叫.mongorc.js
你可以寫你想在連接時(shí)執(zhí)行的內(nèi)容
//mystartupfile
prompt=/*…*/
//getting notmasterandslaveok=false errorsdrivesmenuts,
//soI moverridingthegetDB()codetoALWAYSsetslaveok=true
Mongo.prototype.getDB=function(name){
this.setSlaveOk();
returnnewDB(this,name);
}
/*andsoon…*/
看完上述內(nèi)容,你們掌握 MongoDB1.9.1 中有哪些定制化功能的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注丸趣 TV 行業(yè)資訊頻道,感謝各位的閱讀!
向 AI 問一下細(xì)節(jié)