[JAVA-2610] Connecting to mongdb cloud, getting timeouts Created: 22/Sep/17  Updated: 27/Oct/23  Resolved: 03/Oct/17

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: John McCosker Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Really new to mongodb, using connect string from atlas cloud version (3.4.7) and Java driver version (mongo-java-driver-3.4.3.jar)

getting this exception
Exception in thread "main" com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[{address=duneorbit-shard-00-02-dwjjr.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception=

{com.mongodb.MongoSocketOpenException: Exception opening socket}

, caused by {java.net.ConnectException: Connection refused: connect}}, {address=duneorbit-shard-00-00-dwjjr.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception=

{com.mongodb.MongoSocketOpenException: Exception opening socket}

, caused by {java.net.ConnectException: Connection refused: connect}}, {address=duneorbit-shard-00-01-dwjjr.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception=

{com.mongodb.MongoSocketOpenException: Exception opening socket}

, caused by {java.net.ConnectException: Connection refused: connect}}]
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:377)
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75)
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71)
at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:415)
at com.mongodb.operation.CreateCollectionOperation.execute(CreateCollectionOperation.java:376)
at com.mongodb.operation.CreateCollectionOperation.execute(CreateCollectionOperation.java:53)
at com.mongodb.Mongo.execute(Mongo.java:845)
at com.mongodb.Mongo$2.execute(Mongo.java:828)
at com.mongodb.MongoDatabaseImpl.createCollection(MongoDatabaseImpl.java:198)
at com.mongodb.MongoDatabaseImpl.createCollection(MongoDatabaseImpl.java:169)
at com.jspeedbox.test.TestCloudConnection.main(TestCloudConnection.java:20)

Code snippet:

MongoClientURI uri = new MongoClientURI("mongodb://duneorbit:************@duneorbit-shard-00-00-dwjjr.mongodb.net:27017,"
+ "duneorbit-shard-00-01-dwjjr.mongodb.net:27017,"
+ "duneorbit-shard-00-02-dwjjr.mongodb.net:27017/test?ssl=true&replicaSet=Duneorbit-shard-0&authSource=admin");

MongoClient mongoClient = new MongoClient(uri);
MongoDatabase database = mongoClient.getDatabase("test");
database.createCollection("UserProfiles");

IP Whitelist:
192.168.141.26/32 Active

193.120.236.35/32 (includes your current IP address) Active

0.0.0.0/0 (includes your current IP address) Active



 Comments   
Comment by Jeffrey Yemin [ 03/Oct/17 ]

Hi jmccosker@gmail.com,

As we have not heard back from you in some time, we're resolving this issue for now. If you have more information in the future, please comment and we will consider reopening it.

Regards,
Jeff

Comment by Ross Lawley [ 22/Sep/17 ]

Hi jmccosker@gmail.com,

The java code looks ok, but there is a connection issue: Exception opening socket. Please double check in Atlas that the cluster is running and not deploying after a configuration update.

The next thing to check is can connect to the cluster via the shell? If no, it highlights that there is a general connectivity issue. If yes and you still can't connect via the Java driver - then it points to a Java driver configuration issue.

Just to let you know for future reference this jira project is for Java driver bugs or feature requests. The best place for questions regarding Atlas or MongoDB usage or even Java driver specifics is the mongodb-user mailing list or stackoverflow as you will reach a boarder audience there. If your business requires an answer from MongoDB within a set time frame then we do offer production support.

Ross

Generated at Thu Feb 08 08:57:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.