MongoDB problems
MongoDB Replica Set Without a Primary: Why No Member Is Elected, and the Fix
2 December 2026
A replica set elects a primary only when a majority of its voting members can see each other. Without a primary every write fails, with NotWritablePrimary or not primary, while reads that allow secondaries still work. The question is always the same: which voting members are missing, and why.
What every member says
Connect to any member that answers, with mongosh:
rs.status().members.map(m => ({
name: m.name, state: m.stateStr, health: m.health,
lastHeartbeatMessage: m.lastHeartbeatMessage,
optimeDate: m.optimeDate
}))
rs.conf().members.map(m => ({
host: m.host, votes: m.votes, priority: m.priority,
arbiterOnly: m.arbiterOnly, hidden: m.hidden
}))
| What you see | What it means |
|---|---|
Half or more of the voting members are (not reachable/healthy) | No majority: no election can succeed. Bring members back, or the network between them. |
Members up, all SECONDARY, elections keep failing | Members that can vote have priority 0, or the eligible ones are too far behind to win. |
A member in RECOVERING or STARTUP2 | It is catching up or in initial sync and cannot become primary yet. |
| Each side of a network split sees a minority | Neither side can elect. The side that reaches the majority again gets the primary. |
The recovery, in order
- Bring a voting member back. One more voting member up restores the majority, and the election follows within seconds. Look at the member's own log for why it stopped.
- Fix the network between them. Members that run but cannot reach each other count as missing.
lastHeartbeatMessagesays which pair cannot talk. - Check priorities. A member with priority 0 never becomes primary, and a set where every reachable voter has priority 0 has no candidate.
- Force a reconfiguration last. When the lost members will not come back, remove them from the configuration from a surviving member:
Writes that only the lost members had are rolled back or lost. Use it for a member that is gone for good, not for one that is restarting.cfg = rs.conf() cfg.members = cfg.members.filter(m => ["db2:27017", "db3:27017"].includes(m.host)) rs.reconfig(cfg, { force: true }) - Design for the next one. An odd number of voting members, spread over at least three failure domains, keeps a majority when one domain fails.
See it coming
Radar Engine, the detection layer of dbCove, signs in to every member and reports the loss of fault tolerance before the loss of the primary, with no agent on the server:
| Detector | When it fires |
|---|---|
| Member unavailable | A member is down, silent, RECOVERING or in initial sync for 3 minutes: Warning. Critical when one more loss means no primary, or when the data members up are fewer than the write majority. |
| No primary | No member says it is primary on 2 readings in a row: Critical. The finding lists every member with its state, voting members up against the majority, and the last election's reason. |
| Primary changed | A new primary, with the reason in plain words. Warning when the primary changed 3 times in an hour. |
| Replication lag | A secondary falls so far behind that it cannot win an election or keep majority writes. |
dbCove AI reads the replica set's state and history and says which member to bring back first. It changes nothing without your click.
Questions
Why does my MongoDB replica set have no primary?
Fewer than a majority of the voting members can reach each other, or none of the reachable ones may become primary (priority 0, too far behind, in recovery). rs.status() on any member shows which.
How many members does a replica set need to elect a primary?
A majority of the voting members: 2 of 3, 3 of 5. With 2 voting members, losing either one leaves no primary.
Is rs.reconfig with force safe?
It makes the surviving members a new majority, and writes only the lost members had can be rolled back. Use it only for members that will not come back.