Unlock MongoDB ReplicaSet: All Node Types, Roles, and Configuration Tips
MongoDB replicaSet offers various node roles—including data, arbiter, hidden, voting, and delayed nodes—each with distinct advantages and constraints, and the article explains their purposes, best‑practice configurations, and how to add them using appropriate rs commands for robust, automated failover.
mongoDB replicaSet
Background
MongoDB replicaSet is the officially recommended fully automatic disaster‑recovery cluster architecture, replacing the older master‑slave setup.
Key Advantages
Automatic failover without manual intervention.
Strict data synchronization and split‑brain prevention to minimize data loss.
No fixed primary; drivers automatically discover the primary via the replicaSet parameter.
Simple scaling – a single command adds new nodes with real‑time sync.
Rich role system provides flexibility for various scenarios.
Precautions
At least one data node is required.
Pre‑3.0 MongoDB limits total nodes to 7.
If half or more nodes fail, the cluster becomes read‑only.
Prefer an odd number of nodes to avoid split‑brain and ensure quorum.
Data nodes should be at least two; arbiters at least one.
Including voting nodes raises the limit to 12 (7 non‑voting + 5 voting).
Voting node health affects the cluster, hidden nodes do not.
Role Analysis
1. Data Node
Stores full data and can act as PRIMARY or SECONDARY, possessing both election and voting rights. Used to provide database services.
<code>{
"setName" : "bbset",
"ismaster" : true,
"secondary" : false,
"arbiters" : [ "127.0.0.1:17001" ],
"primary" : "127.0.0.1:7002",
"me" : "127.0.0.1:17001",
"maxBsonObjectSize" : 16777216,
"localTime" : ISODate("2013-08-14T10:11:09.571Z"),
"ok" : 1
}</code>Adding a data node (e.g., 127.0.0.1:9001):
<code>rs.add("127.0.0.1:9001")</code>With priority configuration:
<code>rs.add({ "_id": 3, "host": "127.0.0.1:9001", "priority": 5 })</code>2. Arbiter Node
Participates only in elections; stores no data and does not generate an oplog. Recommended to have one arbiter to avoid primary loss.
<code>{
"setName" : "bbset",
"ismaster" : false,
"secondary" : false,
"arbiters" : [ "127.0.0.1:7001" ],
"primary" : "127.0.0.1:7002",
"arbiterOnly" : true,
"me" : "127.0.0.1:17001",
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"localTime" : ISODate("2013-08-14T10:14:42.797Z"),
"ok" : 1
}</code>Adding an arbiter:
<code>rs.addArb("127.0.0.1:9001")</code>3. Hidden Node
Used for backups or analytics; stores full data, replicates from the primary, but is not visible to drivers and never becomes primary (priority 0).
<code>{
"setName" : "bbset",
"ismaster" : false,
"secondary" : false,
"arbiters" : [ "127.0.0.1:7001" ],
"primary" : "127.0.0.1:7002",
"passive" : true,
"hidden" : true,
"me" : "127.0.0.1:7001",
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"localTime" : ISODate("2013-08-14T10:31:58.656Z"),
"ok" : 1
}</code>Adding a hidden node:
<code>rs.add({ "_id": 3, "host": "127.0.0.1:9001", "priority" : 0, "hidden" : true })</code>4. Voting Node
Provides normal read/write service but does not vote (votes:0). Can be added beyond the 7‑node limit, allowing up to 12 nodes total.
<code>{
"_id" : 24,
"host" : "127.0.0.1:7003",
"votes" : 0,
"priority" : 1
}</code>Adding a voting node:
<code>rs.add({ "_id": 3, "host": "127.0.0.1:9001", "votes":0 })</code>5. Delayed Node
Acts like a hidden node but introduces a replication delay (e.g., 3600 seconds) for point‑in‑time recovery.
<code>{
"_id" : 15,
"host" : "127.0.0.1:7001",
"priority" : 0,
"slaveDelay" : 3600,
"hidden" : true
}</code>Adding a delayed node:
<code>rs.add({ "_id" : 3, "host" : "127.0.0.1:9001", "slaveDelay" : 3600 })</code>With this overview you now understand all replicaSet node roles and can configure them to build a resilient MongoDB cluster.
360 Zhihui Cloud Developer
360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.