Mongodb – Add Secondary to Replica Set in MongoDB Windows

mongodb

I am trying to add the second replica set to primary.

Primary = 192.168.56.52:27017
Secondary = 192.168.56.136:27017

    # mongod.conf

    # for documentation of all options, see:
    #   http://docs.mongodb.org/manual/reference/configuration-options/

    # Where and how to store data.
    storage:
      dbPath: **mypath**\DBs
      journal:
        enabled: true
    #  engine:
    #  mmapv1:
    #  wiredTiger:

    # where to write logging data.
    systemLog:
      destination: file
      logAppend: true
      path:  **mypath**\mongod.log

    # network interfaces
    net:
      port: 27017
      bindIp: 0.0.0.0


    #processManagement:

    #security:
    #operationProfiling:

    replication:
      replSetName: configServers

    #sharding:

    ## Enterprise-Only Options:

    #auditLog:

    #snmp:
    #mp:

But when I try I add
rs.add("192.168.56.136:27017")
It shows as picture .
result
Please help to get run replicaset. Thanks.
I run on windows and start replicaset with service .

Best Answer

As per the error message says, you have added the Primary node of the replica set as localhost. The rule is all nodes of the replica set should be localhost or all should be hostname/ip address.

If you run rs.status() from primary, you will see the primary replica set member as localhost. So when you try to add a secondary with rs.add("192.168.56.136:27017") the system will throw an error.

How to correct this?

conf = rs.conf()

update the hostname of primary member in conf variable

then run

rs.reConfig(conf)

Now add the secondary member.