MongoDB1.9.1中有哪些定制化功能

39次阅读
没有评论

共计 1466 个字符,预计需要花费 4 分钟才能阅读完成。

自动写代码机器人,免费开通

MongoDB1.9.1 中有哪些定制化功能,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

MongoDB1.9.1 有哪些定制化的功能

简单的字符串定义

myReplSetName:SECONDARY prompt=

//ah,bliss

//somesysadminsthink isaweirdprompt,asit salso

//usedforredirections,sotheymightprefer$

prompt= $

$

$//therewego

函数式定义

prompt=function(){returndb+}

test usefoo

foo usebar

bar

更复杂的函数

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 机器

prompt=function(){

…result=db.adminCommand({isdbgrid:1});

…if(result.ok==1){

…return mongos

…}

…return

…}

告诉你当前的时间

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)

另一个新功能是自动加载的配置文件,类似于.bashrc,这个文件会叫.mongorc.js

你可以写你想在连接时执行的内容

//mystartupfile

prompt=/*…*/

//getting notmasterandslaveok=false errorsdrivesmenuts,

//soI moverridingthegetDB()codetoALWAYSsetslaveok=true

Mongo.prototype.getDB=function(name){

this.setSlaveOk();

returnnewDB(this,name);

}

/*andsoon…*/

看完上述内容,你们掌握 MongoDB1.9.1 中有哪些定制化功能的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注丸趣 TV 行业资讯频道,感谢各位的阅读!

向 AI 问一下细节

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-04发表,共计1466字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)