Intermediate LevelMongoDB & Mongoose
How does a Replica Set automatically elect a new Primary during node failure?
❓ Interview Prompt: Explain Replica Set election algorithm, heartbeat loss detection, priority settings, and oplog optime comparison.
When Secondaries detect a heartbeat loss from the Primary node (after 10 seconds), an election is triggered. The node with highest priority and most up-to-date Oplog wins the election.
Code Implementation Example
typescript
console.log('Replica Set Primary election triggered automatically upon heartbeat timeout');💡Replica Set auto-healing election workflow.
🎯 Interview Key Takeaway
Replica Sets automatically elect a new Primary node within seconds during network or hardware failures.
#Primary Election#Failover#Replica Sets#Intermediate
Back to all MongoDB & Mongoose Questions→