mongodb replica set adds two ways to remove nodes
- 2020-05-07 20:37:16
- OfStack
1. Use rs.reconfig to add and delete nodes
1. Add a node
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 a node
repmore:PRIMARY> rs.reconfig(config); // Enable configuration
repmore:PRIMARY> rs.status(); // View node status
Node added successfully.
Note: the replSet of the new node should be the same as other nodes
2. Delete the node
repmore:PRIMARY> config = {_id:"repmore",members:[{_id:0,host:'127.0.0.1:27017',priority :2}]}; // Remove nodes
repmore:PRIMARY> rs.reconfig(config); // Enable configuration
repmore:PRIMARY> rs.status(); // View node status
2. Add and delete nodes using rs.add and rs.remove
repmore:PRIMARY> rs.add("127.0.0.1:27018"); // Add a node
repmore:PRIMARY> rs.remove("127.0.0.1:27018"); // Delete section
Note: rs.add and rs.remove are used without rs.reconfig.