Add Members to Replica Set
How to add members to replica set:
- To get latest ID from members, connect to primary MongoDB replica set then
rs.status
, you will see the latest “_id” of member

Latest Members _id: 2. Which Mean I Got 3 Server Running on Replica Set
-
Add replica set members as hidden replica
#in this case I already add _id:3, _id:4 , _id:5 #priority 0 mean it cannot vote or become primary #hidden so it invisible to our running app rs.add({_id:6, host: "192.168.1.6:27017", priority: 0, hidden: true})

Add Replica Set Members

New Members Status Will Be ‘Startup’
- You can check replication health, status or delay with
rs.config()
,rs.status()
orrs.printSecondaryReplicationInfo()

rs.conf() Output

rs.printSecondaryReplicationInfo() Output
Notes:
-
I added this new members at peak hour, nothing goes down. I assume it was safe to add members even your replica set on busy state.
-
Try to use same specification with main replica to avoid any error on hidden replica
-
Don’t forget to copy your mongo replica key to hidden replica server and change key owner to “mongod:mongod”
-
Sorry for inconsistent screenshot MongoDB _id …
Remove Members from Replica Set
How to remove members replica set:
- Login to mongoshell at primary MongoDB replica set:
rs.remove("192.168.1.6:27017")

Remove Members Success
Notes:
-
I removed members replica set at peak hour (high server workload).
It makes my primary replica set goes down & the application that connect to this MongoDB goes down too.
Even though it was hidden member and got priority=0.
And the worst is removal proccess was failed.
-
Then I tried again to remove replica set members outside peak hour (low hardware usage), nothing goes down and removal proccess was success.
Conclusion
-
For safety reason, please add and remove replica set members outside peak hour.
-
Always add new members as a hidden members and give it priority=0
-
To promote hidden members as normal members you can use
cfg = rs.conf() cfg.members[0].priority = 1 cfg.members[0].hidden = false rs.reconfig(cfg) #if above command doesnt work var config = rs.conf(); config.members.forEach(function(member) { if (member._id === 6) { member.hidden = false; member.priority = 1; } });
-
Do with your own risk!!!

If you feel this website help you, you can donate at saweria