1

I want to setup a replicasetup in my local machine,I am using to instances of mongodb(mongod1.conf,mongod2.conf), rs initiated mongo1 on port 27018 and i want to add the members to 27018 , rs.add('ThinkPad-X230:27019') it is throwing an error called

commands :

mongod --replSet Replicaset1 --dbpath home/data --port 27018
mongo --port 27018
>> rs.initiate()
>> rs.add("ThinkPad-X230:27019")

mongod --dbpath home/data2 --port 27019

mongo --port 27019

i have checked the db.serverStatus().host in 27019 port and adding host name "ThinkPad-X230:27019" to rs.add() members it is throwing the error.

{
    "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,
    "codeName" : "NewReplicaSetConfigurationIncompatible",
    "operationTime" : Timestamp(1568943205, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1568943205, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}
venkatesh
  • 141
  • 3
  • 13

1 Answers1

1

As you started your first instance of mongod with --replSet Replicaset1 option, it is configured to be a part of Replicaset1 replica set.

And when you initialised the replica set, this instance was added to the replica set as a member. Below is the output snippet of rs.status()

{
    "_id" : 0,
    "name" : "localhost:27018",
    "health" : 1,
    "state" : 1,
    "stateStr" : "PRIMARY",
    "uptime" : 228,
    "optime" : {
        "ts" : Timestamp(1569751005, 1),
        "t" : NumberLong(1)
    },
    "optimeDate" : ISODate("2019-09-29T09:56:45Z"),
    "electionTime" : Timestamp(1569750830, 2),
    "electionDate" : ISODate("2019-09-29T09:53:50Z"),
    "configVersion" : 3,
    "self" : true
}

As you can see the name of the member is "localhost:2018".

So, when you try to add another member to this replica set as rs.add('ThinkPad-X230:27019'), it gives you the following error which is a valid error to be thrown, as one member is "localhost:2018" and another which you are trying to add is "ThinkPad-X230:27019" and both must be localhost.

"errmsg" : "Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2"

Try to add the member using the following command,

rs.add("localhost:27019")

And it will be added successfully.

Shubham Vaishnav
  • 1,637
  • 6
  • 18
  • HI Shubham vaishnav , when the mongod instance 20018 is running then and only i am able to open a mongo shell in 20018 , can i know how to enable mongod 20018 instance run forever – venkatesh Nov 06 '19 at 09:01
  • @venkatesh, I didn't get you, you want to run `mongod` instance forever, it will run until it is stopped or an issue arises. – Shubham Vaishnav Nov 07 '19 at 09:34
  • @vaishnav , i want to run mongod --replSet Replicaset1 --dbpath home/data --port 27018 forever like we do for default port 27017 using systemctl as service – venkatesh Nov 07 '19 at 11:36
  • @venkatesh, Then you can create a custom systemd service for mongoDB with your configuration and then you can also run your mongoDB as a service – Shubham Vaishnav Nov 09 '19 at 19:15