Error while adding a secondary instance in mongodb replica set

Anuj Jain picture Anuj Jain · Apr 20, 2015 · Viewed 12.4k times · Source

I am trying to deploy mongodb replica set . I have made my mongodb instance as primary of the replica . Now i am trying to add another mongodb instance hosted at different iP address, as secondary of the replica, but i am getting the following error :

    rs0:PRIMARY> rs.add("<ip address>:27017")
{
    "ok" : 0,
    "errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2",
    "code" : 103
}

What I am doing wrong ?

Answer

Fizer Khan picture Fizer Khan · Dec 20, 2015

I face this issue when i tried to run two mongod instance in same machine. It throws error when i provide like

   rs.add("localhost:27027")
   (or)
   rs.add("127.0.0.1:27027")

where 27027 is the port number of secondary.

Solution:

Pass the hostname instead of ip address

  rs.add("myhostname:27027")