Mongodb – mongo db-Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2

mongodb

while adding secondary member in replica set, i get following error:
"Either all host names in a replica set configuration must be localhost references, or none must be; found 1 out of 2"
my first machine configuration is:enter image description here

enter image description here

enter image description here

second node config:
enter image description here

Best Answer

You can have all replica set nodes in the same physical computer (localhost), but in different ports! (node1:27017, node2:27027, ...)

You CANNNOT have different RS nodes:

  • at one machine at same port (f.ex. 27017)
  • different machine and bind to localhost address

So, you need to build your replica set using IP-addresses.