我刚刚创建了一个免费的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 atlas页面获得的连接字符串。mongodb+srv://admin_eventdb:<PASSWORD>@experimental-1-epdri.mongodb.net/test?retryWrites=true
请帮忙解决这个问题。
5条答案
按热度按时间lawou6xi1#
请尝试:
soat7uwm2#
我有相同的issue。通过使用Java驱动程序3.4的连接字符串,它将是:
而不是
<PASSWORD>
我写自己的密码。admin1
是我的管理员用户。**更新:**如果你想使用驱动程序
3.7+
,你需要写而不是格式连接(并避免我上面的问题)使用
MongoClients.create()
(as of the 3.7 release),的另一变体:**注:**密码不需要像
mongodb://user:<mypassword>@...
那样书写,只需采用mongodb://user:mypassword@...
,不带大括号<>
。xuo3flqw3#
vcudknz34#
对于Node.js: checkout Atlas MongoDB连接
kb5ga3dv5#
刚刚尝试使用Atlas。这是我使用Sping Boot 2.3.1.RELEASE时使用的配置