Add Members to Replica Set

How to add members to replica set:

  1. 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

Latest Members _id: 2. Which Mean I Got 3 Server Running on Replica Set

  1. 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

Add Replica Set Members

New Members Status Will Be ‘Startup’

New Members Status Will Be ‘Startup’

  1. You can check replication health, status or delay with rs.config(), rs.status() or rs.printSecondaryReplicationInfo()
rs.conf() Output

rs.conf() Output

rs.printSecondaryReplicationInfo() Output

rs.printSecondaryReplicationInfo() Output

Notes:

  1. 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.

  2. Try to use same specification with main replica to avoid any error on hidden replica

  3. Don’t forget to copy your mongo replica key to hidden replica server and change key owner to “mongod:mongod”

  4. Sorry for inconsistent screenshot MongoDB _id …


Remove Members from Replica Set

How to remove members replica set:

  1. Login to mongoshell at primary MongoDB replica set:
    rs.remove("192.168.1.6:27017")
    
Remove Members Success

Remove Members Success

Notes:

  1. 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.

  2. Then I tried again to remove replica set members outside peak hour (low hardware usage), nothing goes down and removal proccess was success.


Conclusion

  1. For safety reason, please add and remove replica set members outside peak hour.

  2. Always add new members as a hidden members and give it priority=0

  3. 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; 
        }
    });
    
  4. Do with your own risk!!!


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