com.mongodb.MongoTimeoutException: Timed out after 20000 ms while waiting for a

1,844 views
Skip to first unread message

navaneet...@gmail.com

unread,
Mar 7, 2018, 4:28:22 PM3/7/18
to mongodb-user
this is my java code:

MongoClientOptions mc = MongoClientOptions.builder().sslEnabled(false).sslInvalidHostNameAllowed(true).serverSelectionTimeout(20000).build();

        MongoDatabase mydatabase = mongoClient.getDatabase("dbname");

im getting the following error:


com.mongodb.MongoTimeoutException: Timed out after 20000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=mongodb://<username>:<password>@name-shard-00-01-nsbco.mongodb.net:27017,name-shard-00-00-nsbco.mongodb.net:27017,name-shard-00-02-nsbco.mongodb.net:27017/oakrreports?ssl=true&replicaset=name-shard-0&authsource=admin:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongodb://<username>:<password>@name-shard-00-01-nsbco.mongodb.net:27017,name-shard-00-00-nsbco.mongodb.net:27017,name-shard-00-02-nsbco.mongodb.net:27017/dbname?ssl=true&replicaset=name-shard-0&authsource=admin}, caused by {java.net.UnknownHostException: mongodb://<username>:<password>@oakanalytics-shard-00-01-nsbco.mongodb.net:27017,name-shard-00-00-nsbco.mongodb.net:27017,name-shard-00-02-nsbco.mongodb.net:27017/dbname?ssl=true&replicaset=name-shard-0&authsource=admin}}]
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.getReadConnectionSource(ClusterBinding.java:63)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:406)
at com.mongodb.operation.ListDatabasesOperation.execute(ListDatabasesOperation.java:102)
at com.mongodb.operation.ListDatabasesOperation.execute(ListDatabasesOperation.java:54)
at com.mongodb.Mongo.execute(Mongo.java:836)
at com.mongodb.Mongo$2.execute(Mongo.java:823)
at com.mongodb.OperationIterable.iterator(OperationIterable.java:47)
at com.mongodb.OperationIterable.forEach(OperationIterable.java:70)
at com.mongodb.MappingIterable.forEach(MappingIterable.java:50)
at com.mongodb.MappingIterable.into(MappingIterable.java:60)
at com.mongodb.Mongo.getDatabaseNames(Mongo.java:470)

Kevin Adistambha

unread,
Mar 9, 2018, 12:03:41 AM3/9/18
to mongodb-user

Hi

It looks like you’re trying to connect to MongoDB Atlas using the Java driver. Is this correct?

If yes, you might be able to follow the steps outlined in the Java driver example. Please ensure that you are using the latest Java driver

If you’re still having issues connecting to Atlas, you might want to click on the Support button on the sidebar to get Atlas-specific support.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages