Spring Boot 以及如何配置到 MongoDB 的连接详细信息? [英] Spring Boot and how to configure connection details to MongoDB?
问题描述
作为 Spring Boot 的新手,我想知道如何为 MongoDB 配置连接详细信息.我已经尝试了正常的例子,但没有一个涵盖连接细节.
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.
我想指定将要使用的数据库以及运行 MongoDB 的主机的 url/端口.
I want to specify the database that is going to be used and the url/port of the host that runs MongoDB.
有什么提示或技巧吗?
推荐答案
只是引用 引导文档:
您可以设置 spring.data.mongodb.uri
属性来更改 url,或者指定一个 host/port
.例如,您可以在 application.properties
中声明以下内容:
You can set
spring.data.mongodb.uri
property to change the url, or alternatively specify ahost/port
. For example, you might declare the following in yourapplication.properties
:
spring.data.mongodb.host=mongoserver
spring.data.mongodb.port=27017
spring.data.mongodb
前缀的所有可用选项都是 MongoProperties
的字段:
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;
这篇关于Spring Boot 以及如何配置到 MongoDB 的连接详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!