Replica Set Members in MongoDB (original) (raw)

Last Updated : 24 Feb, 2026

A replica set in MongoDB is a group of MongoDB instances that store the same data. Replica sets provide redundancy, ensuring data is always available, even during server failures. Each member of the replica set plays a different role in maintaining data consistency and high availability.

Types of Replica Set Members in MongoDB

MongoDB supports several types of members in a replica set, each with distinct responsibilities.

client_application

1. Primary Member

In a MongoDB replica set, one node is elected as the primary to handle all writes; if it becomes unreachable, a new primary is automatically elected. The primary logs all changes in the oplog for secondaries to replicate.

2. Secondary Member

Secondary members in a MongoDB replica set replicate data from the primary’s oplog to maintain identical copies and support high availability, failover, and read scaling.

3. Arbiter

An arbiter in a MongoDB replica set does not store data; it only participates in elections to help maintain quorum and select a primary.

Adding Replica Set Member

Setting up and managing MongoDB replica set members is essential for ensuring high availability and redundancy. Here’s how to add members to your MongoDB replica set. To add members to a replica set, follow these steps:

Add a New Member

To add a new member to an existing replica set, connect to the primary member of the replica set and use the rs.add() command.

rs.add("hostname:port")

Add an Arbiter (if needed)

Arbiters help in maintaining an odd number of voting members in a replica set. To add an arbiter:

rs.addArb("arbiterHost:port")

Adding a Hidden Member

Hidden members are replica set members that do not participate in elections or serve read requests. They are useful for backup purposes. To add a hidden member

var cfg = rs.conf();
cfg.members.push({
_id: ,
host: "hiddenHost:port",
priority: 0,
hidden: true
});
rs.reconfig(cfg);

Add a Delayed Member

A delayed member is used for replication with a delay. This can be useful for disaster recovery. To add a delayed member:

var cfg = rs.conf();
cfg.members.push({
_id: ,
host: "delayedHost:port",
priority: 0,
hidden: true,
slaveDelay:
});
rs.reconfig(cfg);

Add a Non-Voting Member

Non-voting members do not participate in elections and have no vote in primary selection. To add a non-voting member:

var cfg = rs.conf();
cfg.members.push({
_id: ,
host: "nonVotingHost:port",
votes: 0
});
rs.reconfig(cfg);

Configuration and Troubleshooting Issues

When configuring a MongoDB replica set, you may encounter certain issues. Here are some common ones: