Site icon Tutorial

Add Members to a Replica Set

Add Members to a Replica Set

A replica set can have a maximum of seven voting members. To add a member to a replica set that already has seven votes, you must either add the member as a non-voting member or remove a vote from an existing member. In production deployments you can configure a control script to manage member processes. You can use these procedures to add new members to an existing set. You can also use the same procedure to “re-add” a removed member. If the removed member’s data is still relatively recent, it can recover and catch up easily.

If you have a backup or snapshot of an existing member, you can move the data files (e.g. the dbPath directory) to a new system and use them to quickly initiate a new member. The files must be:

Requirements

The procedure is as

Prepare the Data Directory – Before adding a new member to an existing replica set, prepare the new member’s data directory using one of the following strategies:

Add a Member to an Existing Replica Set

mongod –dbpath /srv/mongodb/db0 –replSet rs0

To view replica set status, issue the rs.status() method.

Configure and Add a Member – You can add a member to a replica set by passing to the rs.add() method a members document. The document must be in the form of a local.system.replset.members document. These documents define a replica set member in the same form as the replica set configuration document. Specify a value for the _id field of the members document. MongoDB does not automatically populate the _id field in this case. Finally, the members document must declare the host value. All other fields are optional. As an example to add a member with the following configuration:

Issue the following:

rs.add({_id: 1, host: “mongodb3.example.net:27017”, priority: 0, hidden: true})

Apply for MongoDB Certification Now!!

https://www.vskills.in/certification/databases/mongodb-server-administrator

Back to Tutorial

Exit mobile version