Add a new primary to a replica set

so I have a 3 node setup of mongodb replica set, but the data is older than the production database. So my initial idea to make every node existing on the replica set priority 0.5 and add the production DB to the replicaset with priority 1 so he will become the new primary and the secondary will sync with production and then I can unplug the production database again.

My question is I never done it, idk if it will work.

is better to just make a dump of production and restore it on primary node?

Hi @Israel_Joaquim,

You are trying to sync the DEV cluster with the latest version of the data from PROD, correct?

In that case, the easiest way to do that is to stop the mongod on one of the secondary node in the PROD cluster, take a copy of the database folder (the one in --dbpath) and restart the secondary node in PROD.

Then you can copy that DB folder on the 3 DEV nodes and start a new DEV cluster with a different --replSet name to make sure it doesn’t try to communicate with the PROD. You will have to update the replica set config with the new IPs, but that should be it.

If you are lazy, you can also only copy the DB folder one one DEV node and just start the 2 other nodes empty and then add them in the Replica Set. This will trigger the initial sync and copy everything for you but I guess this takes a bit more time than a manual copy of the entire folder.

Cheers,
Maxime.

2 Likes