How to modify replica set config?
mongodb
Solution
You can use force option when reconfiguring replica set:
rs.reconfig(config, {force: true})
Note that, as Adam already suggested in the comments, you should have at least 3 nodes: 2 full nodes and 1 arbiter (minimum supported configuration) or 3 full nodes (minimum recommended configuration) so that primary node can be elected.
Problem
I have a mongo 2 node cluster running, with this replica set config. ``` config = {_id: "repl1", members:[ {_id: 0, host: 'localhost:15000'}, {_id: 1, host: '192.168.2.100:15000'}] } ``` I have to move these both nodes on to new servers. I have copied everything from old to new servers, but I'm running into issues while reconfiguring the replica config due to ip change on the 2nd node. I have tried this. ``` config = {_id: "repl1", members:[ {_id: 0, host: 'localhost:15000'}, {_id: 1, host: '192.168.2.200:15000'}] } rs.reconfig(config) { "startupStatus" : 1, "errmsg" : "loading local.system.replset config (LOADINGCONFIG)", "ok" : 0 } ``` It shows above message, but change is not happening. I also tried changing replica set name but pointing to the same data dirs. I am getting the following error: ``` rs.initiate() { "errmsg" : "local.oplog.rs is not empty on the initiating member. cannot initiate.", "ok" : 0 } ``` What are the right steps to change the IP but keeping the data on the 2nd node, or do i need to recreate/resync the 2nd node?