rs.status() is a mongosh helper for inspecting the current health, roles, and replication state of MongoDB replica-set members. It provides a script-friendly alternative to db.printSecondaryReplicationInfo() and helps identify primary, secondary, unreachable, synchronizing, or rollback states. section 9.1.1 section 9.1.3
Use the returned member information to:
- Confirm which member is PRIMARY and which members are SECONDARY. section 9.1.1
- Detect STARTUP, STARTUP2, RECOVERING, DOWN, UNKNOWN, ROLLBACK, or REMOVED conditions. section 9.1.1
- Check whether secondaries are synchronized with the primary and identify replication lag. section 9.1.3
Inspect member states
Run rs.status() in mongosh, or extract a compact result with db.adminCommand("replSetGetStatus").members.map((m) => ({ _id: m._id, name: m.name, state: m.state, stateStr: m.stateStr })). A typical three-member result shows one PRIMARY and two SECONDARY members. section 9.1.1
Listing 9.1 Output of the replSetGetStatus command
db.adminCommand("replSetGetStatus").members.map((m) =>
➥({ _id: m._id, name: m.name, state: m.state, stateStr: m.stateStr }))
[
{
_id: 0,
name: 'ac-5dhjxpf-shard-00-00.fpomkke.mongodb.net:27017'
state: 2,
stateStr: 'SECONDARY'
},
{
_id: 1,
name: 'ac-5dhjxpf-shard-00-01.fpomkke.mongodb.net:27017'
state: 1,
stateStr: 'PRIMARY'
},
{
_id: 2,
name: 'ac-5dhjxpf-shard-00-02.fpomkke.mongodb.net:27017'
state: 2,
stateStr: 'SECONDARY'
}
]
Browse a compact status projection showing each member's identifier, host, numeric state, and readable state name. section 9.1.1
