Spring Boot以及如何配置与MongoDB的连接详细信息? [英] Spring Boot and how to configure connection details to MongoDB?

查看:477
本文介绍了Spring Boot以及如何配置与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 a host/port. For example, you might declare the following in your application.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆