【问题标题】:Specifying multiple servers in mongoDB connection string prevents it from connecting, but only specifying the primary server works在 mongoDB 连接字符串中指定多个服务器会阻止其连接,但仅指定主服务器有效
【发布时间】:2021-04-14 03:48:54
【问题描述】:

我们有 4 个 mongoDB 服务器,其中第一个是当前具有 3 个副本的主服务器。如果我在连接字符串中指定了所有 4 台服务器,它根本无法连接,但如果我只指定第一个服务器,它就可以正常连接。这很糟糕,因为如果第一台服务器出现故障,它将无法连接。

这有效: mongodb://login:password@server1:27017/admin?readPreference=Primary

这不起作用: mongodb://login:password@server1:27017,server2:27017,server3:27017,server4:27017/admin?readPreference=Primary

例外: 使用 CompositeServerSelector{ Selectors = WritableServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } } 选择服务器 30000 毫秒后发生超时。集群状态的客户端视图是 { ClusterId : "1", ConnectionMode : "Automatic", Type : "ReplicaSet", State : "Connected", Servers : [{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/server1: 27017" }", EndPoint: "Unspecified/server1:27017", State: "Disconnected", Type: "Unknown", HeartbeatException: "MongoDB.Driver.MongoConnectionException: 打开与服务器的连接时发生异常。

尝试连接的服务在 Kube 上运行。

知道为什么会这样吗?

【问题讨论】:

    标签: mongodb exception kubernetes database-connection connection-string


    【解决方案1】:

    您需要将模式添加到连接字符串:replicaSet=myRepl

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多