DBAtlas · Database operations atlas

Force a replica set reconfiguration after losing the majority (force reconfig)

MongoDBReplica Set

Command

// On a surviving member with the most recent optime (runs as a secondary):
rs.status().members.map(m => ({ host: m.name, state: m.stateStr, health: m.health, optime: m.optimeDate }))
cfg = rs.conf()
cfg.members.map((m, i) => ({ i: i, host: m.host }))
// Keep only the reachable members (example: members 0 and 2):
cfg.members = [cfg.members[0], cfg.members[2]]
rs.reconfig(cfg, { force: true })
// Verify the new primary election:
rs.status().members.map(m => ({ host: m.name, state: m.stateStr }))

What it does

When the majority of voting members is permanently lost (e.g. a whole data center is gone), builds a new config from the surviving members so the set can elect a primary again.

When to use it

Only in a disaster scenario: the majority will not come back and the set is stuck read-only.

Caution

This is a last resort. If the lost members return later with the old config, split-brain and rollback can occur; isolate them from the network and, when bringing them back, wipe their data and add them with an initial sync. Pick the member with the most recent optime; otherwise writes not majority-committed on other members fall into rollback. Do not use force for routine membership changes.

Open in DBAtlas →

Related