我刚刚创建了一个免费的MongoDB Atlas集群实例。但是由于某种原因,我无法从应用程序以及MongoDB Compas进行连接。
当我尝试运行我的应用程序时,出现错误提示。
Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is {type=UNKNOWN, servers=[{address=experimental-1-epdri.mongodb.net:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: experimental-1-epdri.mongodb.net}, caused by {java.net.UnknownHostException: experimental-1-epdri.mongodb.net}}]
at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:377) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:411) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:144) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.operation.CreateIndexesOperation.execute(CreateIndexesOperation.java:71) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.Mongo.execute(Mongo.java:845) ~[mongodb-driver-3.4.2.jar:na]
at com.mongodb.Mongo$2.execute(Mongo.java:828) ~[mongodb-driver-3.4.2.jar:na]
at com.mongodb.MongoCollectionImpl.createIndexes(MongoCollectionImpl.java:491) ~[mongodb-driver-3.4.2.jar:na]
at com.mongodb.MongoCollectionImpl.createIndex(MongoCollectionImpl.java:458) ~[mongodb-driver-3.4.2.jar:na]
at org.axonframework.mongo.eventsourcing.eventstore.AbstractMongoEventStorageStrategy.ensureIndexes(AbstractMongoEventStorageStrategy.java:201) ~[axon-mongo-3.0.5.jar:3.0.5]
at org.axonframework.mongo.eventsourcing.eventstore.MongoEventStorageEngine.ensureIndexes(MongoEventStorageEngine.java:123) ~[axon-mongo-3.0.5.jar:3.0.5]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:311) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:134) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
... 76 common frames omitted
Process finished with exit code 1
在Compas上,它只是说MongoDB实例不在此位置运行。我已经检查了群集,然后看到以下内容。
但是我仍然无法连接到mongo集群。此外,我还在Mongo CLI上尝试过,发现错误如下所示。
下面是我从MongoDB地图集页面获得的连接字符串。
mongodb+srv://admin_eventdb:<PASSWORD>@experimental-1-epdri.mongodb.net/test?retryWrites=true
请帮助解决此问题。
答案 0 :(得分:1)
请尝试:
Hostname: experimental-1-epdri.mongodb.net
SRV Record: checked
Authentication: Username / Password
Username: admin_eventdb
Password: <PASSWORD>
Authentication Database: admin
Replica Set Name:
Read Preference: Primary
SSL: System CA / Atlas Deployment
SSL Tunnel: None
答案 1 :(得分:0)
我有相同的https://developers.facebook.com/docs/unity/reference/current/FB.ShareLink。通过使用Java Driver 3.4的连接字符串,它将是:
mongodb://user:<PASSWORD>@cluster0-shard-00-00-ox90k.mongodb.net:27017,cluster0-shard-00-01-ox90k.mongodb.net:27017,cluster0-shard-00-02-ox90k.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true
我写了自己的密码,而不是<PASSWORD>
。 admin1
是我的管理员用户。
已更新:如果要使用驱动程序3.6+
,则需要编写而不是格式化连接
MongoClientURI uri = new MongoClientURI("mongodb+srv://admin1:mypassword@cluster0-ox90k.mongodb.net/test?retryWrites=true");
MongoClient mongoClient = new MongoClient(uri);
MongoClient mongoClient = MongoClients.create("mongodb+srv://admin1:mypassword@cluster0-ox90k.mongodb.net/test?retryWrites=true");
注意:密码需要类似于mongodb://user:<mypassword>@...
的形式写,只是格式为mongodb://user:mypassword@...
,不用大括号<>
。
答案 2 :(得分:0)
用于Node.js :结帐Atlas MongoDB connection
library(dplyr)
df1 %>%
tidyr::fill(holiday, .direction = 'up') %>%
group_by(holiday) %>%
mutate(new_holiday = replace(holiday, row_number() < n() - 2, NA))
# date holiday new_holiday
# <date> <chr> <chr>
# 1 2019-12-18 Christmas NA
# 2 2019-12-19 Christmas NA
# 3 2019-12-20 Christmas NA
# 4 2019-12-21 Christmas NA
# 5 2019-12-22 Christmas NA
# 6 2019-12-23 Christmas Christmas
# 7 2019-12-24 Christmas Christmas
# 8 2019-12-25 Christmas Christmas
# 9 2019-12-26 New Year NA
#10 2019-12-27 New Year NA
#11 2019-12-28 New Year NA
#12 2019-12-29 New Year NA
#13 2019-12-30 New Year New Year
#14 2019-12-31 New Year New Year
#15 2020-01-01 New Year New Year
答案 3 :(得分:0)
只是尝试使用Atlas。这是适用于Spring Boot 2.3.1.RELEASE
的配置spring:
data:
mongodb:
database: sample_training
uri: mongodb+srv://<user>:<pass>@cluster0-hosturl.aws|gcp.mongodb.net/?retryWrites=true&w=majority