QA
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→

More MongoDB & Mongoose Interview Questions

Beginner LevelMongoDB & Mongoose

How does the MongoDB Aggregation Pipeline work? Explain $match, $group, $lookup, and $project.

Beginner LevelMongoDB & Mongoose

What is MongoDB and how does the BSON document data model work?

Beginner LevelMongoDB & Mongoose

What is the structure of a MongoDB ObjectId and how is it generated?