The primary is the only member in the replica set that receives write operations. If for some reason primary may becomes unavailable & an election determines the new primary. Which is not expected in few occasion. Election happens due to hardware issue or may be someone accidentally shutdown the primary which lead to this unwanted selection.On other note you may want one of your secondary to act as primary. You can achieve this forcefully and here is how you do it.
Solution To Problem
Say we have 3 note replica set, 3 physically separated machines.
192.168.1.0 – the current primary.
192.168.1.1 – a secondary.
192.168.1.2 – a secondary .
Our goal is to make 192.168.1.2 primary
From mongo shell, connect to current primary. use the following sequence of operations.
Now connect to a secondary. use the following sequence of operations.
wait for 120 seconds
You will see machine with IP 192.168.1.2 is now became primary.