连接到 MongoDB 个副本集导致 "Expecting replica set member, but found a STANDALONE"

Connecting to MongoDB replica set results in "Expecting replica set member, but found a STANDALONE"

我正在尝试通过 Quarkus 上的应用程序 运行 连接到我的本地 MongoDB 副本集(通过 Docker Compose 配置),但是我很快收到以下错误当我尝试通过应用程序访问数据库时:

2022-01-24 14:51:03,170 ERROR [org.mon.dri.cluster] (cluster- ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo1:27017) Expecting replica set member, but found a STANDALONE.  Removing mongo1:27017 from client view of cluster.
2022-01-24 14:51:03,177 ERROR [org.mon.dri.cluster] (cluster-ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo3:27017) Expecting replica set member, but found a STANDALONE.  Removing mongo3:27017 from client view of cluster.
2022-01-24 14:51:03,182 ERROR [org.mon.dri.cluster] (cluster-ClusterId{value='61eeaec706f79a375f4b4c19', description='null'}-mongo2:27017) Expecting replica set member, but found a STANDALONE.  Removing mongo2:27017 from client view of cluster.
2022-01-24 14:51:08,179 ERROR [nl.rab.kno.int.LoggingInterceptor] (executor-thread-0) LoggingInterceptor.MethodCallEvent(className=nl.rabobank.knowledge.service.PreferencesService, methodName=getLanguagesForUser, result=EXCEPTION, exception=com.mongodb.MongoTimeoutException: Timed out after 5000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate@31e1baef. Client view of cluster state is {type=REPLICA_SET, servers=[])

出于某种原因,它似乎将我的节点标识为独立节点,而不是副本集成员,之后它们将从集群的客户端视图中删除。我想知道这里出了什么问题?

这是我在 Quarkus 应用程序中使用的连接字符串:

quarkus:
    mongodb:
        connection-string: mongodb://mongo1:27021,mongo2:27022,mongo3:27023/database?replicaSet=dbrs

我只是按照本指南在 MongoDB 中设置副本集 Docker 撰写:https://blog.tericcabrel.com/mongodb-replica-set-docker-compose/.

这些是我的 Quarkus 应用程序(版本 2.6.2)使用的依赖项:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-mongodb-client</artifactId>
</dependency>
<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-mongodb-panache</artifactId>
</dependency>

您忘记告诉您的节点,它们属于一个副本集! 你有两个选择,命令行:

mongod --replSet "rs0" --bind_ip localhost,<hostname(s)|ip address(es)>

或配置文件内部

replication:
   replSetName: "rs0"
net:
   bindIp: localhost,<hostname(s)|ip address(es)>

查看来自 here!

的更多信息

看来我找到问题了。在我的本地计算机上删除 Mongo 后,我设法消除了该特定错误,导致只有 Mongo 作为我的容器化节点的一部分。

但是,我现在 运行 进入另一个问题,为此我创建了这个 post:Connecting to containerised MongoDB replica set with Docker results in "Canonical address ... does not match server address."