MongoDB replica set add 2 ways to delete a node _mongodb

Source: Internet
Author: User
Tags mongodb

One, using Rs.reconfig, to add, delete nodes

1, add nodes

repmore:primary> config = {_id: "Repmore", Members:[{_id:0,host: ' 127.0.0.1:27017 ', Priority:2},{_id:1,host: ' 127.0.0.1:27018 ', priority:1}]};  Add node 
 
repmore:primary> rs.reconfig (config);  Make configuration effective 
 
repmore:primary> rs.status ();   View node Status 

Node added successfully.
Note: The Replset of the new node will be the same as the other nodes

2, delete the node

repmore:primary> config = {_id: "Repmore", Members:[{_id:0,host: ' 127.0.0.1:27017 ', Priority:2}]};   Delete node 
 
repmore:primary> rs.reconfig (config);  Make configuration effective 
 
repmore:primary> rs.status ();  View node Status 

Second, use Rs.add and rs.remove to add delete nodes

Repmore:primary> Rs.add ("127.0.0.1:27018");   Add node 
 
repmore:primary> rs.remove ("127.0.0.1:27018");//Delete section 

Note: Using Rs.add and Rs.remove is not a rs.reconfig to use the configuration to take effect.

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.