Reputation: 27
I have set up docker and created four containers (each having single mongodb instance installed with authetication enabled) to enable mongodb replication with arbiter. I have also expose mongodb's 27017
port to host machine so that outer application should able to connect it but I am not able to connect with my JAVA Spring Application from Eclipse.
Following is mongo uri I used:
mongodb://username:[email protected]:18088,192.168.1.102:18089,192.168.1.102:18099/?authSource=dbName;replicaSet=rs0;readPreference=secondaryPreferred;authMechanism=SCRAM-SHA-1;waitQueueMultiple=100
Exception
"Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@739c3a21. Client view of cluster state is {type=REPLICA_SET, servers=[{address=mongo3:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo3}, caused by {java.net.UnknownHostException: mongo3}}, {address=mongo2:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo2}, caused by {java.net.UnknownHostException: mongo2}}, {address=mongo1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo1}, caused by {java.net.UnknownHostException: mongo1}}, {address=mongorb:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongorb}, caused by {java.net.UnknownHostException: mongorb}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@739c3a21. Client view of cluster state is {type=REPLICA_SET, servers=[{address=mongo3:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo3}, caused by {java.net.UnknownHostException: mongo3}}, {address=mongo2:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo2}, caused by {java.net.UnknownHostException: mongo2}}, {address=mongo1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo1}, caused by {java.net.UnknownHostException: mongo1}}, {address=mongorb:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongorb}, caused by {java.net.UnknownHostException: mongorb}}]"
Upvotes: 0
Views: 952
Reputation: 776
This bit:
{address=mongo3:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo3}, caused by {java.net.UnknownHostException: mongo3}}
is being repeated for each of your mongo instances, and essentially it means that your mongo instances are unreachable, since mongorb
, mongo1
, mongo2
and mongo3
aren't being adequately mapped to the corresponding IPs.
It also appears as if you're trying to map each of the instances to a different port on 192.168.1.102
, yet your code is making all requests on the default port, 27017
.
I'm not familiar with Eclipse or Spring, but you should probably configure the host, IP and port for each instance, and then it should run fine.
Upvotes: 1