How Elections Work in MongoDB
When a secondary server(say node2) cannot reach a primary(node1), it will contact all the other members in replica set (node 3,4...) and request that it should be elected as primary.
These other members(node 3,4,..) do several checks
Can they reach the primary server(node1) that the member(node2) which is seeking election cannot reach?
Is the member seeking election(node2) is in sync , i.e whether it up to date with replication
Is there any other server with a higher priority available who should be elected instead?
If a member seeking election (node 2) receives “yes” from a majority of the set,it becomes primary.If even one server vetoes the election, the election is cancelled.
A member vetoes an election when it knows any reason that the member seeking election (node2) shouldn't become primary. The member seeking election (node 2) must be up to date with replication, as far as the members it can reach know. All replicated operations are strictly ordered by ascending timestamp, so the candidate must have operations later than or equal to any member it can reach. A common point of confusion is that members always seek election for themselves. For simplicity’s sake, neighbors cannot “nominate” another server to be primary, they can only vote for it if it is seeking election. Why an odd number is recommended in replSet for MongoDB
If you loose a single member in a 3 members replica set, it's the same as loosing a single member in a 4 members replica set: you still gain quorum majority and a new primary can be elected (the replset can still elect a new master by majority). On the other hand, if you loose two members in a 3 members replica set or a 4 members replica set (or n/2 members of n-members replica set) - again - the impact is the same: No new leader can be voted by election. References: http://docs.mongodb.org/master/core/replica-set-elections/






