I would like to lower the timeout setting in my spring-mongo java application (the query should fail after 300 ms if the database is not accessible).
I tried this c
I found the answer here: https://scalegrid.io/blog/understanding-mongodb-client-timeout-options/
@Bean
public MongoDbFactory mongoDbFactory() throws Exception {
MongoClientOptions.Builder optionsBuilder = MongoClientOptions.builder();
optionsBuilder.connectTimeout(300);
optionsBuilder.socketTimeout(300);
optionsBuilder.serverSelectionTimeout(300);
return new SimpleMongoDbFactory(new MongoClientURI(mongoUri, optionsBuilder));
}