When MongoDB cluster is set up with replica set, one of the secondaries will take the role of the primary when Master is down. In case of a failure, the switch should be processed automatically. One of the remaining secondaries calls for an election to select a new primary and automatically resume normal operations.
The median time before a cluster elects a new primary should not typically exceed 12 seconds, assuming default replica configuration settings. This includes time required to mark the primary as unavailable and call and complete an election. You can tune this time period by modifying the settings.electionTimeoutMillis replication configuration option. Factors such as network latency may extend the time required for replica set elections to complete, which in turn affects the amount of time your cluster may operate without a primary.
Replica set members send heartbeats (pings) to each other every two seconds. If a heartbeat does not return within 10 seconds, the other members mark the delinquent member as inaccessible.
To check the cluster status, run the following command from any member of the replica set :
It shows the status as that particular member sees it.
The following command gives you some basic info about the whole set, including whether the current member is master or not and who the other members are.