# MongoServerError: ReplicaSetMonitor: election failed for set rs0

- **ID:** `mongodb/replica-set-election-failed`
- **Domain:** mongodb
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The replica set election failed due to a tie or network partition preventing a majority of nodes from agreeing on a primary.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## Workarounds

1. **Force a new election by stepping down the current primary with a specific timeout: rs.stepDown(60, { force: true })** (85% success)
   ```
   Force a new election by stepping down the current primary with a specific timeout: rs.stepDown(60, { force: true })
   ```
2. **Temporarily increase electionTimeoutMillis on all nodes to allow more time for consensus: cfg = rs.conf(); cfg.settings.electionTimeoutMillis = 15000; rs.reconfig(cfg)** (90% success)
   ```
   Temporarily increase electionTimeoutMillis on all nodes to allow more time for consensus: cfg = rs.conf(); cfg.settings.electionTimeoutMillis = 15000; rs.reconfig(cfg)
   ```
3. **If a tie persists, manually set a node's priority to 0 to remove it from contention, then reconfig: cfg = rs.conf(); cfg.members[1].priority = 0; rs.reconfig(cfg)** (80% success)
   ```
   If a tie persists, manually set a node's priority to 0 to remove it from contention, then reconfig: cfg = rs.conf(); cfg.members[1].priority = 0; rs.reconfig(cfg)
   ```

## Dead Ends

- **** — Restarting nodes doesn't resolve the underlying voting deadlock; it may reset timers but the same tie condition persists. (70% fail)
- **** — rs.stepDown() only triggers a new election without addressing the root cause of the tie. (60% fail)
- **** — Adding more nodes doesn't automatically break ties; it requires adjusting electionTimeoutMillis or priority settings. (80% fail)
