MongoDB Documentation, Release 3.0.4 The following procedures change the members’ hostnames as follows: • mongodb0.example.net:27017 (the primary) • mongodb1.example.net:27017 • mongodb2.example.net:27017 1. For each secondary in the replica set, perform the following sequence of operations: (a) Stop the secondary. (b) Restart the secondary at the new location. (c) Open a mongo shell connected to the replica set’s primary. In our example, the primary runs on port 27017 so you would issue the following command: (d) Use rs.reconfig() to update the replica set configuration document (page 652) with the new host- name. (e) Make sure your client applications are able to access the set at the new location and that the secondary has a chance to catch up with the other members of the set. 2. Open a mongo shell connected to the primary and step down the primary using the rs.stepDown() method: 3. When the step down succeeds, shut down the old primary. 4. Start the mongod instance that will become the new primary in the new location. 5. Connect to the current primary, which was just elected, and update the replica set configuration document (page 652) with the hostname of the node that is to become the new primary. 6. Open a mongo shell connected to the new primary. Use the most appropriate procedure for your deployment. Change Hostnames while Maintaining Replica Set Availability This procedure uses the above assumptions (page 642). For example, the following sequence of commands updates the hostname for the secondary at the array index 1 of the members array (i.e. members[1] ) in the replica set configuration document: cfg = rs.conf() cfg.members[1].host = "mongodb1.example.net:27017" rs.reconfig(cfg) For more information on updating the configuration document, see replica-set-reconfiguration-usage . Repeat the above steps for each non-primary member of the set. rs.stepDown() The replica set elects another member to the become primary. For example, if the old primary was at position 0 and the new primary’s hostname is mongodb0.example.net:27017 , you would run: cfg = rs.conf() cfg.members[0].host = "mongodb0.example.net:27017" rs.reconfig(cfg) 9.3. Replica Set Tutorials 643 mongo --port 27017