I know that if I create a connection to MongoDB in Java to a replica set using a list of ServerAddresses (using this function) with ReadPreference.SECONDARY
, the client will balance the reads across the replica set, preferring nodes with shorter round-trip times (the same colo, for example).
But when I create a MongoDB client to a bunch of MongoS servers with ReadPreference.SECONDARY
, all reads/writes go to the first server in the list, even when the access is cross-colo and a MongoS exists in the same colo.
For example, if I have three MongoS servers - SF1, SF2, and NYC1 (in that order) - my clients only talk to SF1, regardless of whether they're in SF or NYC.
Is there something I have to configure or a different way to set up the client when talking to MongoS servers? What am I missing?