I am trying to set a connection timeout for the MongoClient (driver version 2.13).
It hangs for 10 seconds then it times out. I need a fast timeout because this code is used in test.
Here is my code:
String connectionUri = properties.getProperty("application.mongo.url");
System.out.println("****** "+ connectionUri + "*******");
MongoClientOptions mongoClientOptions = MongoClientOptions.builder()
.connectTimeout(500)
.build();
MongoClient mongoClient = new MongoClient(connectionUri, mongoClientOptions);
The javadoc is describes the connectTimeout and this post describes how to set a timeout.
Has anyone had similar issues and resolved it?