如何使用 ReactiveMongo 指定 replicaSet 名称?

How to specify the replicaSet name with ReactiveMongo?

当使用 ReactiveMongo 打开到多个 mongoDB 服务器的连接时,我们可以将要连接的主机列表传递给它。

但是我找不到提供副本集名称的任何方法(正如我们在标准 MongoDB URI 中所做的那样)。甚至 ReactiveMongo 的 URI 解析器也会忽略它。

有问题吗?在不知道副本集名称的情况下,驱动程序是否可以正常工作?

您提供的列表名为 "seed list"。当您的驱动程序连接到这些服务器之一时,无论是主服务器还是辅助服务器,驱动程序都会被告知它连接到副本集以及哪个服务器是当前的主服务器(如果有的话)。

你的驱动程序甚至应该在新的主选出时得到通知,并且它应该自动连接到新选出的主选出。

根据ReactiveMongo docs 你应该通读:

[...]ReactiveMongo provides support for Replica Sets. That means the following:

  • the driver will detect if it is connected to a Replica Set;
  • it will probe for the other nodes in the set and connect to them;
  • it will detect when the primary has changed and guess which is the new one;

[...]