Reputation: 55
I set up a new Spring Boot Application including only the spring-boot-starter-data-mongodb
dependency and added basic mongodb configs (host, port, username, password, ..) in the application.properties.
When I execute the application the following appears in the console:
2020-12-27 23:30:21.306 INFO 25230 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:86}] to localhost:27017
2020-12-27 23:30:21.306 INFO 25230 --- [localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:87}] to localhost:27017
I am curios why the connection was opened twice by spring. Isn't one opened connection enough?
Upvotes: 2
Views: 1533
Reputation: 140
Please add the below line into your properties file.
spring.data.mongodb.min-connections-per-host=1
The default size is 2 for the MongoDB java driver.
Hope this will work for you!
Upvotes: 4