ReactiveMongo 无法连接到 ReplicaSet,错误为“无效节点状态主要(预期:未知)”

ReactiveMongo failed to connect to ReplicaSet with error `Invalid node status Primary (expected: Unknown)`

我们有一个来自阿里云的MongoDB副本集。我们将 MongoDB URL 设置为

mongodb://username:password@dds-xxxxx-pub.mongodb.rds.aliyuncs.com:3717,dds-xxxxx-pub.mongodb.rds.aliyuncs.com:3717/admin?replicaSet=mgset-xxxxx

服务器启动时,ReactiveMongo 抛出错误:

Invalid node status Primary for dds-2zedbafbdcdae6541787-pub.mongodb.rds.aliyuncs.com:3717 (expected: Unknown); Fallback to Unknown status

我查看了 ReactiveMongo 的源代码,但无法理解为什么它需要 unknown 状态?

upSet.updateAll { n =>
          if (node.names.contains(n.name) && // the node itself
            n.status != node.status) {
            // invalidate node status on status conflict
            warn(s"Invalid node status ${node.status} for ${node.name} (expected: ${n.status}); Fallback to Unknown status")

            n._copy(status = NodeStatus.Unknown)
          } else n
        }

在忽略 replicaSet 选项后它对我们有效。

http://reactivemongo.org/releases/0.1x/documentation/tutorial/alibaba-apsaradb.html

Finally for ReactiveMongo connection, the replicaSet option can be removed from the URI, and the password placeholder must be replaced with the actual value.

mongodb.uri = "mongodb://root:${APSARADB_PASSWORD}@dds-4e6322c0290348c49176-pub.mongodb.germany.rds.aliyuncs.com:3717/${APSARADB_DBNAME}"