Adding a replica in MongoDB throws an error
Solution 1
The missing point is that the instance that I was trying to add did not have mongod instance started at the port defined. The given connection parameters hence were incorrect, and that caused the communication problem.
Solution 2
The actual error is couldn't initialize connection to host developer-ViratualBox, address is invalid
, Simply the primary node is not able to connect with secondery nodes. check connections, firewall, and check connection with mongo shell whether you can access that port or not.
Solution 3
While starting secondary mongod process use --replSet option the try to run rs.add("localhost:27002") from primary mongod shell.
Solution 4
While creating rsconf
file please enter <localhost:port>
instead of <hostname:port>
.
And then reconfig(rsconf)
.
example :
rs0:PRIMARY>
rsconf = {
_id: "rs0",
members: [
{
_id: 0,
host: "**localhost**:port for primary rs"
}]
}
rs0:PRIMARY> rs.initiate(rsconf)
{
"info" : "try querying local.system.replset to see current configuration",
"ok" : 0,
"errmsg" : "already initialized",
"code" : 23
}
If you are getting above error then use the below command:
rs0:PRIMARY> rs.reconfig(rsconf)
Adding secondary node : rs.add("localhost:port for secondary rs")
Hope it will work.
compuhosny
I'm a passionate developer. I believe in what I do, and that's why I don't do what I don't believe in :)
Updated on July 09, 2022Comments
-
compuhosny almost 2 years
I'm trying to add a node to a replica set using
rs.add("developer-ViratualBox:30103")
and I'm getting the following error message:{ "ok" : 0, "errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: developer-VirtualBox:30101; the following nodes did not respond affirmatively: developer-ViratualBox:30103 failed with Failed attempt to connect to developer-ViratualBox:30103; couldn't initialize connection to host developer-ViratualBox, address is invalid", "code" : 74 }
The node is already running and I'm connected to it using
mongo
shell. What could possibly be the problem?