MongoDB:当主副本关闭时,MongoClient无法连接到辅助副本集

MongoDB:当主副本关闭时,MongoClient无法连接到辅助副本集,mongodb,mongodb-replica-set,Mongodb,Mongodb Replica Set,在我的场景中,我希望MongoClient(Meteor应用程序)在主Mongo关闭时连接到MongoDB辅助副本集。我设置了一个5集群,其中当3个MongoDB关闭时,其余2个将作为辅助服务器启动,在此期间,MongoClient应继续与辅助Mongo建立连接,并以只读模式运行 有人试过这个吗 我有各种各样的休息时间 Cluster created with settings {hosts=[10.1.1.10:4000], mode=MULTIPLE, requiredClusterType

在我的场景中,我希望MongoClient(Meteor应用程序)在主Mongo关闭时连接到MongoDB辅助副本集。我设置了一个5集群,其中当3个MongoDB关闭时,其余2个将作为辅助服务器启动,在此期间,MongoClient应继续与辅助Mongo建立连接,并以只读模式运行

有人试过这个吗

我有各种各样的休息时间

Cluster created with settings {hosts=[10.1.1.10:4000], mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='5 ms', maxWaitQueueSize=2000, requiredReplicaSetName='rs0'}
INFO  | 2020-08-19 08:29:02,880 | 10.2.2.11 | org.mongodb.driver.cluster | Adding discovered server 10.1.1.10:4000 to client view of cluster
INFO  | 2020-08-19 08:29:02,999 | 10.2.2.11 | org.mongodb.morphia.logging.MorphiaLoggerFactory | LoggerImplFactory set to org.mongodb.morphia.logging.jdk.JDKLoggerFactory
INFO  | 2020-08-19 08:29:03,036 | 10.2.2.11 | org.mongodb.driver.cluster | Exception in monitor thread while connecting to server 10.1.1.10:4000

No server chosen by ReadPreferenceServerSelector{readPreference=primaryPreferred} from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=10.1.1.10:4000, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]}. Waiting for 5 ms before timing out
有人看到过这个错误吗

这就是流星如何连接到mongod

mongodb://username:password@host-01:4000,host-02:4000,host-03:4000,host-04:4000,host-05:4000/mydb?replicaSet=rs0
readPreference is PrimaryPreferred

任何驱动程序都应允许您在知道至少一个次要/次要首选/主要首选读取首选项时发出具有次要/次要首选/主要首选读取首选项的查询


部署中没有任何功能性的辅助数据库,或者应用程序和数据库之间存在某种连接问题,这会导致服务器未知,而不是辅助数据库。

我将PrimaryPreferred作为我的读取首选项。我的二级数据库可以正常工作,因为我可以通过shell acan查看rs.status()显示二级状态更正r0:secondary>rs.status(){“set”:“rs0”,“myState”:2,“term”:NumberLong(5),“heartbeatIntervalMillis”:NumberLong(2000),},“members”:[{“\u id”:3,“name”:“1.3.2.21:4000”,“health”:1,“state”:2,“stateStr”:“SECONDARY”,“uptime”:1779,“infoMessage”:“找不到要从中同步的成员”,“self”:true},{“\u id”:4,“name”:“1.3.2.22:4000”,“health”:1,“state”:2,“stateStr”:“SECONDARY”,}],“ok”:1}rs0:SECONDARY>,这使得连接问题成为可能的原因。异常/日志告诉您驱动程序正在连接到什么,调试这些连接不工作的原因。