Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1767

listCollections helper fails with direct connection to a secondary

      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

      {readPreference=primary}

      .
      Client view of cluster state is {type=REPLICA_SET, servers=[

      {address=sg-302test6-1063.devservers.mongodirector.com:27017, type=REPLICA_SET_SECONDARY, roundTripTime=2.8 ms, state=C ONNECTED}

      ]

      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.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            dharshanr@scalegrid.net Dharshan Rangegowda
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: