In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
#! / bin/bashecho-e "\ n\ n*~~DATE:" `date'+% Y/%m/%d% T'` "~
© 2024 shulou.com SLNews company. All rights reserved.