MongoDB Learning Note 32 MongoDB modifying replica set configuration

Source: Internet
Author: User

One, delete replica set members

Spock:primary> rs.config ()    {              "_id"  :  "Spock",              "Version"  : 1,             "members " : [                     {                              "_id"  : 0,                               "Host"  :  "192.168.1.112:27017"                       },                    {                               "_id"  : 1,                               "Host"  :  "192.168.1.113:27017"                      }             ]    }    spock:PRIMARY>  rs.remove ("192.168.1.113:27017")     {              "ErrMsg"  :  "Exception: can ' t find self in new  replset config ",             "Code"  : 13433,              "OK"  : 0    }     spock:primary> rs.remove ("192.168.1.112:27017")     2015-02-02t21 : 59:13.303+0800 dbclientcursor::init call ()  failed    2015-02-02t21 : 59:13.304+0800 error: error doing query: failed at src/mongo/shell/ query.js:81    2015-02-02t21:59:13.305+0800 trying reconnect to  127.0.0.1:27017  (127.0.0.1)  failed    2015-02-02T21:59:13.308+0800  reconnect 127.0.0.1:27017  (127.0.0.1)  ok    spock:PRIMARY>  Rs.config ()     {             "_ ID " : " Spock ",              "Version"  : 2,              "Members"  : [                     {                               "_id"  : 1,                              "Host"  :  "192.168.1.113:27017"                      }             ]    }


second, add replica set members

Spock:primary> rs.add ("192.168.1.112:27017")     {  "OK"  : 1 }     spock:primary> rs.config ()     {              "_id"  :  "Spock",              "Version"  : 3,              "Members"  : [                     {                               "_id"  : 1,                              "Host"  :  " 192.168.1.113:27017 "                     },                     {                              "_id"  : 2,                               "Host"  :  "192.168.1.112:27017"                      }             ]    }



From the above process, the version field in the configuration document will be self-increment, its initial value is 1;

Third, or modify the replica set through the Rs.reconfig () function

For example, host name is used instead of IP address

[[email protected] ~]# ping host113   ping host113  (192.168.1.113 )  56 ( bytes of data.    64 bytes from host113 ) ( 192.168.1.113): icmp_seq=1 ttl=64 time=0.060 ms    64 bytes  from host113  (192.168.1.113): icmp_seq=2 ttl=64 time=0.030 ms     64 bytes from host113  (192.168.1.113):  icmp_seq=3 ttl=64 time=0.026  ms    64 bytes from host113  (192.168.1.113):  icmp_seq=4  ttl=64 time=1.04 ms    --- host113 ping statistics ---     4 packets transmitted, 4 received, 0% packet loss,  time 3001ms    rtt min/avg/max/mdev = 0.026/0.289/1.041/0.434  ms  &Nbsp; [[email protected] ~]# mongo    mongodb shell version:  2.6.7    connecting to: test    spock:PRIMARY>  rs.config ()     {                  "_id"  :  "Spock",                  "Version"  : 3,                  "Members"  : [                                          {  " _id " : 1, " host " : " 192.168.1.113:27017 "},                     {  "_id"  : 2,  "host"  :  " 192.168.1.112:27017 "}                             ]      }    spock:primary> var config=rs.config ()    spock: Primary> config.members[0].host= "host113:27017"     host113:27017     spock:primary> rs.reconfig (config)     2015-02-02T22:21:22.793+0800  Dbclientcursor::init call ()  failed    2015-02-02t22:21:22.795+0800 trying  reconnect to 127.0.0.1:27017  (127.0.0.1)  faile2015-02-02T22:21:22.797+0800  reconnect 127.0.0.1:27017  (127.0.0.1)  ok    reconnected to server  after rs command&nbSP; (which is normal) spock:primary> rs.config ()    {                  "_id"  :  "Spock",                  "Version"  : 4,                  "Members"  : [                                 {  "_id"  : 1, "host"  :  "host113:27017"},             {  "_id"  : 2,  "host"  :  "192.168.1.112:27017"}                              ]    }    spock:primary> 

For complex replica set configurations, Rs.reconfig function modifications are more useful than rs.add and rs.remove;

This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1610912

MongoDB Learning Note 32 MongoDB modifying replica set configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.