I was able to fix it after taking two steps.
First one:
Preparation of the appropriate MongoClientSettings object containing the key settings for our Mongo client.
private MongoClientSettings getMongoClientSettings() {
return MongoClientSettings.builder()
.retryWrites(true)
.applyToConnectionPoolSettings(poolSettings -> poolSettings
.minSize(5)
.maxSize(300)
.maxConnectionIdleTime(0, TimeUnit.MILLISECONDS))
.applyToSocketSettings(socketSettings -> socketSettings
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES))
.build();
}
maxConnectionIdleTime – the maximum time a connection can be unused. A zero value indicates no limit to the idle time.
maxSize - The maximum number of connections allowed. Those connections will be kept in the pool when idle. Once the pool is exhausted, any operation requiring a connection will block waiting for an available connection. Default is 100
minSize - The minimum number of connections. Those connections will be kept in the pool when idle, and the pool will ensure that it contains at least this minimum number. Default is 0
Second one:
Increasing the default timeout in application.properties / application.yaml file (or the one you already have)
mongodb:
database: your_db_name
authDatabase: admin
config:
enabled: true
write:
writeConcern:
isMajority: true
timeout:
milliseconds: 100000
Check it out and it should work :)