## Considerations 

When updating the replica configuration object, access the replica set members in the members array with the array index . The array index begins with 0 . Do not confuse this index value with the value of the _id field in each document in the members array. 

Note: MongoDB does not permit the current primary to have a priority of 0 . To prevent the current primary from again becoming a primary, you must first step down the current primary using rs.stepDown() . 

## Procedure 

This tutorial uses a sample replica set with 5 members. 

## Warning: 

• The rs.reconfig() shell method can force the current primary to step down, which causes an election (page 580). When the primary steps down, the mongod closes all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods. 

• To successfully reconfigure a replica set, a majority of the members must be accessible. If your replica set has an even number of members, add an arbiter (page 614) to ensure that members can quickly obtain a majority of votes in an election for primary. 

Step 1: Retrieve the current replica set configuration. The rs.conf() method returns a replica set configura- tion document (page 652) that contains the current configuration for a replica set. 

In a mongo shell connected to a primary, run the rs.conf() method and assign the result to a variable: 

cfg = rs.conf() 

The returned document contains a members field which contains an array of member configuration documents, one document for each member of the replica set. 

Step 2: Assign priority value of 0 . To prevent a secondary member from becoming a primary, update the secondary member’s priority to 0 . 

To assign a priority value to a member of the replica set, access the member configuration document using the array index. In this tutorial, the secondary member to change corresponds to the configuration document found at position 2 of the members array. 

cfg.members[2].priority = 0 

The configuration change does not take effect until you reconfigure the replica set. 

Step 3: Reconfigure the replica set. Use rs.reconfig() method to reconfigure the replica set with the updated replica set configuration document. 

Pass the cfg variable to the rs.reconfig() method: 

rs.reconfig(cfg) 

