Spring Boot and how to configure connection details to MongoDB?

后端 未结 6 2041
死守一世寂寞
死守一世寂寞 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:28

    Just to quote Boot Docs:

    You can set spring.data.mongodb.uri property to change the url, or alternatively specify a host/port. For example, you might declare the following in your application.properties:

    spring.data.mongodb.host=mongoserver
    spring.data.mongodb.port=27017
    

    All available options for spring.data.mongodb prefix are fields of MongoProperties:

    private String host;
    
    private int port = DBPort.PORT;
    
    private String uri = "mongodb://localhost/test";
    
    private String database;
    
    private String gridFsDatabase;
    
    private String username;
    
    private char[] password;
    

提交回复
热议问题