Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What customization functions are available in MongoDB1.9.1

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report