Mongodb – n automatic way for a secondary member to promote to primary member in a replica set

mongodbmongodb-4.2replication

Here is my setup:

Node 1 = 10.1.0.1 (Primary) - priority 1
Node 2 = 10.1.0.2 (Secondary) - priority 1
Node 3 = 10.1.0.3 (Secondary) - priority 0

In the event of Node 1 failure, Node 2 will be set to Primary of the mongo replica set.

Once Node 1 is already accessible, is there a way to automatically promote it to Primary and Node 2 will be set to Secondary again once Node 1 catches up on the replica set?

Best Answer

Yes, easily! Set priority of node 1 to higher than 1...

Node 1 = 10.1.0.1 (Primary) - priority 2
Node 2 = 10.1.0.2 (Secondary) - priority 1
Node 3 = 10.1.0.3 (Secondary) - priority 0.5