Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a replica in MongoDB throws an error

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?

like image 784
compuhosny Avatar asked May 27 '15 10:05

compuhosny


People also ask

What is true about replication in MongoDB?

In simple terms, MongoDB replication is the process of creating a copy of the same data set in more than one MongoDB server. This can be achieved by using a Replica Set. A replica set is a group of MongoDB instances that maintain the same data set and pertain to any mongod process.

What causes replication lag in MongoDB?

MongoDB replication lag occurs when the secondary node cannot replicate data fast enough to keep up with the rate that data is being written to the primary node.

How does replica set connect to MongoDB?

To connect to a replica set deployment, specify the hostname and port numbers of each instance, separated by commas, and the replica set name as the value of the replicaSet parameter in the connection string. In the following example, the hostnames are host1 , host2 , and host3 , and the port numbers are all 27017 .


3 Answers

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.

like image 84
Laxmikant Dange Avatar answered Oct 03 '22 21:10

Laxmikant Dange


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.

like image 45
compuhosny Avatar answered Oct 03 '22 21:10

compuhosny


While starting secondary mongod process use --replSet option the try to run rs.add("localhost:27002") from primary mongod shell.

like image 27
Raju Lalli Avatar answered Oct 03 '22 22:10

Raju Lalli