MongoDB replica sets elect primary nodes via modified Raft consensus. When heartbeats miss the electionTimeoutMillis threshold (default 10s), secondaries trigger elections.
A candidate requires majority quorum (N/2 + 1) and the highest optime to win. During network partitions, an isolated primary unable to see a majority automatically steps down to secondary, eliminating concurrent divergent writes.