Updated on 2026-08-17 GMT+08:00

Replica Set

A replica set consists of a set of mongod processes. It is a collection of nodes that help ensure data redundancy and reliability.

For details about mongod processes, see the MongoDB official documentation.

A replica set consists of three nodes: primary, secondary, and hidden. The three-node architecture is set up automatically, and the three nodes automatically synchronize data with each other to ensure data reliability. Replica sets are recommended for small- and medium-sized service systems that require high availability.

  • Primary node: Primary nodes are used to process both read and write requests.
  • Secondary node: Secondary nodes are used to process read requests only.
  • Hidden node: Hidden nodes are used to back up service data.

You can manually perform a primary/standby switchover. If the primary node fails, the system automatically promotes a secondary node to primary to ensure high availability. The following figure shows the replica set architecture.

Figure 1 Three-node replica set architecture

After a three-node replica set instance is created, you can add nodes up to either 5 or 7. The newly added nodes are secondary nodes. For details about how to add nodes for a replica set instance, see Changing Replica Set Instance Nodes.

Figure 2 Replica set instance nodes