The main factor here is the Replica Set Elections.
Replica sets use elections to determine which set member will become primary. Replica sets can trigger an election in response to a variety of events, such as:
- Adding a new node to the replica set,
- Initiating a replica set,
- Performing replica set maintenance using methods such as
- The secondary members losing connectivity to the primary for more
than the configured timeout (10 seconds by default).
I think this is what you are looking for:
instructs the primary of the replica set to become a secondary. After the primary steps down, eligible secondaries will hold an election for a new primary.
Another option would be that you can force a replica set member to become primary by giving it a higher
members[n].priority value than any other member in the set. Note that a majority of the configured members of a replica set must be available for a replica set to reconfigure or elect a primary.