# MongoServerError: ReplicaSetMonitor: 副本集 rs0 选举失败

- **ID:** `mongodb/replica-set-election-failed`
- **领域:** mongodb
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

副本集选举失败，因为平局或网络分区阻止大多数节点就主节点达成一致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## 解决方案

1. ```
   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)
   ```
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)
   ```

## 无效尝试

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