Spring Boot and how to configure connection details to MongoDB?

后端 未结 6 2046
死守一世寂寞
死守一世寂寞 2020-12-12 18:45

Being new to Spring Boot I am wondering on how I can configure connection details for MongoDB. I have tried the normal examples but none covers the connection details.

6条回答
  •  旧巷少年郎
    2020-12-12 19:20

    It's also important to note that MongoDB has the concept of "authentication database", which can be different than the database you are connecting to. For example, if you use the official Docker image for Mongo and specify the environment variables MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD, a user will be created on 'admin' database, which is probably not the database you want to use. In this case, you should specify parameters accordingly on your application.properties file using:

    spring.data.mongodb.host=127.0.0.1
    spring.data.mongodb.port=27017
    spring.data.mongodb.authentication-database=admin
    spring.data.mongodb.username=
    spring.data.mongodb.password=
    spring.data.mongodb.database=
    

提交回复
热议问题