-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 3.0.0
-
Component/s: Cluster Management
According the the server selection specification, when directly connected to a single MongoDB server command helpers like listCollections that intentionally ignore the default read preference on MongoDatabase should still send the command to the server, even if it's a non-primary member of a replica set.
Currently the driver fails to execute listCollections and other similar command when directly connected to a non-primary replica set member.
===============================================
Original Description:
Hi,
I am not able to get to connect to the secondary using secondaryPreferred global preference. Here is my code
MongoClientOptions options = new MongoClientOptions.Builder().connectTimeout(20000).readPreference(ReadPreference.secondaryPreferred()).serverSelectionTimeout(12000).build();
....
m = new MongoClient(new ServerAddress(host, port), creds, options);
When the provided host is a secondary of a replica set the code fails with the following error
Timed out after 12000 ms while waiting for a server that matches ReadPreferenceServerSelector
.
Client view of cluster state is {type=REPLICA_SET, servers=[
]
Looks like the right readPreference is not being preserved in this case.
If I try to connect to the primary it appears to work fine.
- is duplicated by
-
JAVA-2081 MongoClient does not respect ReadPreference
- Closed