2
votes

I have Error in configuration of Mongodb sharded cluster.

I tried all the possibilities of rs.add("127.0.0.1:27002"), rs.add("loclahost:27002") and rs.add("hostname:27002") for sharding

But I am getting 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 
}
2

2 Answers

0
votes

I assume that you try to connect to your primary and trying to add the secondary nodes. To start a Mongo instance by typing

mongo localhost:30001

I suppose this is primary, in the mongod shell for this primary. Type in this command

rs.status()

You'll get to know the name of your primary. Same will be the name of your secondary with just the difference of the port number.

Once you get the name, just do rs.add("name:port_number") and you'll be able to add.

0
votes

rs.add() is used to make ReplicaSet not Sharded cluster.

If you what to add a shard to a sharded cluster, you may use sh.addShard("host:port").