7. To confirm the new configuration, call rs.conf() in the mongo shell. 

Your output should resemble: 

{ "_id" : "rs", "version" : 4, "members" : [ { "_id" : 0, "host" : "mongodb0.example.net:27017" }, { "_id" : 1, "host" : "mongodb1.example.net:27017" }, { "_id" : 2, "host" : "mongodb2.example.net:27017" } ] } 

## Change All Hostnames at the Same Time 

This procedure uses the above assumptions (page 642). 

1. Stop all members in the replica set . 

2. Restart each member on a different port and without using the --replSet run-time option. Changing the port number during maintenance prevents clients from connecting to this host while you perform maintenance. Use the member’s usual --dbpath , which in this example is /data/db1 . Use a command that resembles the following: 

mongod --dbpath /data/db1/ --port 37017 

3. For each member of the replica set, perform the following sequence of operations: 

(a) Open a mongo shell connected to the mongod running on the new, temporary port. For example, for a member running on a temporary port of 37017 , you would issue this command: 

mongo --port 37017 

(b) Edit the replica set configuration manually. The replica set configuration is the only document in the system.replset collection in the local database. Edit the replica set configuration with the new hostnames and correct ports for all the members of the replica set. Consider the following sequence of commands to change the hostnames in a three-member set: 

use local cfg = db.system.replset.findOne( { "_id": "rs" } ) cfg.members[0].host = "mongodb0.example.net:27017" cfg.members[1].host = "mongodb1.example.net:27017" cfg.members[2].host = "mongodb2.example.net:27017" db.system.replset.update( { "_id": "rs" } , cfg ) 

