What customization functions are available in MongoDB1.9.1
What are the customized functions in MongoDB1.9.1? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
What are the customized functions of MongoDB1.9.1
Simple string definition
MyReplSetName:SECONDARY > prompt= ">"
>
> / / ah,bliss
>
> / / somesysadminsthink > isaweirdprompt,asit'salso
> / / usedforredirections,sotheymightprefer$
> prompt= "$"
$
$/ / therewego
Functional definition
> prompt=function () {returndb+ ">";}
Test > usefoo
Foo > usebar
Bar >
More complex functions
> states= ["STARTUP", "PRIMARY", "SECONDARY", "RECOVERING", "FATAL"
... "STARTUP2", "UNKNOWN", "ARBITER", "DOWN", "ROLLBACK"]
>
> prompt=function () {
... result=db.isMaster ()
... if (result.ismaster) {
.. roomndb + ">"
...}
... elseif (result.secondary) {
.. return "(" + db+ ") >"
...}
... result=db.adminCommand ({replSetGetStatus:1})
... states [result.myState] + ":" + db+ ">"
...}
(test) >
What are the customized functions of MongoDB1.9.1
Tell you if you are connected to a mongos machine
> prompt=function () {
... result=db.adminCommand ({isdbgrid:1})
... if (result.ok==1) {
.. return "mongos >"
...}
.. return ">"
...}
Tell you the current time
> prompt=function () {
... varnow=newDate ()
... returnnow.getHours () + ":" + now.getMinutes () + ":" + now.getSeconds () + ">"
...}
10:30:45 > db.foo.count ()
60000
10:30:46 >
It can also be defined in the configuration file
$# loadfromcommandlinearg:
$mongoshellConfig.js
MongoDBshellversion1.9.1-
Connectingto:test
>
> / / loadfromtheshellitself
> load ("/ path/to/my/shellConfig.js")
Another new feature is an automatically loaded configuration file, similar to .bashrc, which is called .mongorc.js
You can write what you want to do when you connect.
/ / mystartupfile
Prompt=/*...*/
/ / getting "notmasterandslaveok=false" errorsdrivesmenuts
/ / soI'moverridingthegetDB () codetoALWAYSsetslaveok=true
Mongo.prototype.getDB=function (name) {
This.setSlaveOk ()
ReturnnewDB (this,name)
}
/ * andsoon...*/
After reading the above, have you mastered the methods of customizing functions in MongoDB1.9.1? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!