java - com.mongodb.MongoSocketException: No such host is known
问题描述
I am trying to connect to MongoDB Atlas DB from my spring boot app. I set the below listed properties in my application properties file. When I try to connect I see this exception "com.mongodb.MongoSocketException: No such host is known". However I am able to connect to this using mongodb compass from the same machine. Am I missing something?
spring.data.mongodb.authentication-database=
spring.data.mongodb.host=
spring.data.mongodb.port=
spring.data.mongodb.username=
spring.data.mongodb.password=
spring.data.mongodb.database=
I am also able to connect when I use the below -
spring.data.mongodb.uri=
解决方案
Take a look at this: https://developer.mongodb.com/article/srv-connection-strings/
Atlas is giving you a connection string with the mongodb+srv syntax where the "host" part is actually a DNS SRV record that gives you a replica set, not a host. This is compatible with the spring.data.mongodb.uri parameter and of course with MongoDb compass.
However setting the spring.data.mongodb.host instead gives you the unknown host exception.
推荐阅读
- angular - 提供者未定义离子
- php - 在 Woocommerce 购物车页面中获取运输方式标题
- android - 在 LifecycleObserver 中使用 LiveData
- c# - 文件存在 c# Visual Studio 2017
- pandas - 将熊猫数据框转换为具有多个键的字典
- xml - 使用 XSLT 2.0 的函数 fn:parse-xml-fragment 是否有任何替代方法?
- angular - 用角度 6 重新排列剑道网格行
- java - Android Studio:如何自动生成从 xml 到 java 类的视图变量?
- ios - UIPickerView 选定的行标题设计在行值等于 1 时未更改
- django - django 2中urlconfs的理想格式/结构是什么