Spring connect to mongodb using username and password

Viewed 3915

I've got mongo DB running on docker. To set username and password I set MONGO_INITDB_DATABASE, MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD variables.

And now on spring boot application a can use URI: mongodb://username:password@host:27017/db_name?authSource=admin and it's working.

Now I want changed properties and it looks like:

spring:
  data:
    mongodb:
      authentication-database: admin
      host: host
      database: db_name
      password: password
      port: 27107
      username: username

Any ideas what is wrong?

springboot: 2.2.5 spring-boot-starter-data-mongodb-reactive

1 Answers

I found that on the documentation:

If you use the Mongo 3.0 Java driver, spring.data.mongodb.host and spring.data.mongodb.port are not supported. In such cases, spring.data.mongodb.uri should be used to provide all of the configuration.

So probably this is the problem and for now I just stay with the URI.

Related