I am using spring boot web application which connects to mongo db which is working out of the box. I just use the following properties:
spring.data.mongodb.h
For Spring Data with Reactive MongoDb:
My case was a bit different (I had closing connections - which throws "Caused by: java.lang.IllegalStateException: state should be: open")
But You can use this with your case.
application.yml:
spring.data.mongodb:
host: localhost
database: myDb
port: 27017
username: admin
password: test
If Your implementation use MongoReactiveAutoConfiguration for bean creation, then You can configure it with this bean:
@Bean
public MongoClientSettings mongoClientSettings() {
final MongoClientSettings clientSettings = MongoClientSettings.builder()
.retryWrites(true)
.applyToConnectionPoolSettings((ConnectionPoolSettings.Builder builder) -> {
builder.maxSize(300) //connections count
.minSize(100)
.maxConnectionLifeTime(0, TimeUnit.MILLISECONDS)
.maxConnectionIdleTime(0, TimeUnit.MILLISECONDS)
.maxWaitTime(5000, TimeUnit.MILLISECONDS)
.maxWaitQueueSize(5000);
})
.applyToSocketSettings(builder -> {
builder.connectTimeout(2000, TimeUnit.MILLISECONDS);
})
.applicationName("app")
.build();
return clientSettings;
}