-1

In my scenario i expect the MongoClient (Meteor app) to connect to MongoDB secondary replica set when Primary Mongo is down. I have a 5 Cluster set up where when 3 MongoDB's are down the remaining 2 will be up as secondary and during this time the MongoClient should continue to establish connection with the secondary Mongo's and operate in a read only mode.

Has anyone tried this ?

I get various time outs

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

Has anyone seen this error ?

This is how meteor connects to 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
Cody MacPixelface
  • 1,348
  • 10
  • 21

1 Answers1

0

Any driver should allow you to issue queries with a secondary/secondary preferred/primary preferred read preference when it is aware of at least one secondary.

You either do not have any functional secondaries in the deployment or you have some sort of connectivity issue between your application and your database, which causes the servers to be unknown rather than secondaries.

D. SM
  • 13,584
  • 3
  • 12
  • 21
  • I have PrimaryPreferred as my read preference. My secondaries are functional since i can connect via shell acan see rs.status() displaying secondary status correctly – Subbu V Aug 20 '20 at 02:52
  • rs0:SECONDARY> rs.status() { "set" : "rs0", "myState" : 2, "term" : NumberLong(5), "heartbeatIntervalMillis" : NumberLong(2000), }, "members" : [ { "_id" : 3, "name" : "1.3.2.21:4000", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 1779, "infoMessage" : "could not find member to sync from", "self" : true }, { "_id" : 4, "name" : "1.3.2.22:4000", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", } ], "ok" : 1 } rs0:SECONDARY> – Subbu V Aug 20 '20 at 02:58
  • That leaves the connectivity issue as the likely cause. – D. SM Aug 20 '20 at 03:21
  • The exception/log tell you what the driver is connecting to, debug why those connections are not working. – D. SM Aug 20 '20 at 03:23