Dozie
Dozie

Reputation: 153

MongoServerError: "No host described in new configuration with {version: 1, term: 0} for replica set rs0 maps to this node," How do I fix this?

Started mongo server using

mongod --port 27018 --dbpath "/usr/local/var/mongodb/data/db0" --replSet rs0 --bind_ip "locahost,0.0.0.0"

And connected to the instance using

mongosh mongodb://127.0.0.1:27018/vndr

Tried to initiate a replica set using rs.initiate()

Then got the error

---
> rs.initiate()
{
    "ok" : 0,
    "errmsg" : "No host described in new configuration with {version: 1, term: 0} for replica set rs0 maps to this node",
    "code" : 93,
    "codeName" : "InvalidReplicaSetConfig"
}

On the server log noticed these lines saying ""Nnadozies-MacBook-Pro.local" not known

{"t":{"$date":"2022-08-18T14:52:20.861+01:00"},"s":"W",  "c":"NETWORK",  "id":21207,   "ctx":"conn1","msg":"getaddrinfo() failed","attr":{"host":"Nnadozies-MacBook-Pro.local","error":"nodename nor servname provided, or not known"}}
{"t":{"$date":"2022-08-18T14:52:25.866+01:00"},"s":"I",  "c":"NETWORK",  "id":4834700, "ctx":"conn1","msg":"isSelf could not connect via connectSocketOnly","attr":{"hostAndPort":"Nnadozies-MacBook-Pro.local:27018","error":{"code":6,"codeName":"HostUnreachable","errmsg":"couldn't connect to server Nnadozies-MacBook-Pro.local:27018, connection attempt failed: HostNotFound: Could not find address for Nnadozies-MacBook-Pro.local:27018: SocketException: Host not found (authoritative)"}}}
{"t":{"$date":"2022-08-18T14:52:25.867+01:00"},"s":"E",  "c":"REPL",     "id":21425,   "ctx":"conn1","msg":"replSetInitiate error while validating config","attr":{"error":{"code":74,"codeName":"NodeNotFound","errmsg":"No host described in new configuration with {version: 1, term: 0} for replica set rs0 maps to this node"},"config":{"_id":"rs0","version":1,"members":[{"_id":0,"host":"Nnadozies-MacBook-Pro.local:27018"}]}}}

Upvotes: 1

Views: 3361

Answers (1)

Dozie
Dozie

Reputation: 153

Followed response in this similar question and added the line 127.0.0.1 Nnadozies-MacBook-Pro.local to my /etc/hosts file to fix this.

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

127.0.0.1 figmadaemon.com

127.0.0.1 Nnadozies-MacBook-Pro.local 

Posting this because the similar question wasn't really clear on how to solve the problem. I think this makes it clearer that the hostname mongodb was looking at could not be resolved to an IP address because it wasn't in /etc/hosts

Tip on editing /etc/hosts: use sudo permissions for write access

Other than that please I'm curious what other way I can run mongodb instances so they use known hostnames.

Upvotes: 3

Related Questions