Carlos Spitzer bio photo

Carlos Spitzer

Senior Consultant at Red Hat

Email Twitter Facebook Google+ LinkedIn Github

For most replica sets, the hostnames in the host field never change. However, if organizational needs change, you might need to migrate some or all host names. If this is your case, take a look at the following procedure:

From mongoDB replica set primary node (in our case, node 1), execute the following commands:

$ mongo 

Then, go to the second node (that maybe has been chosen as the primary node):

$ mongo 
cfg = rs.conf()
cfg.members[0].host = "<new_node_name>:27017"

Before go out mongoDB interpreter, check if everything is OK now:


If you want to go further, I suggest you to check this post.