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

DB.getCollectionNames() fails when connected to a secondary server even if ReadPreference is SECONDARY

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.8.0
    • Affects Version/s: None
    • Component/s: None
    • None

      I want to get the list of collections in my database as reported by a secondary member of my replica set. If I have a Mongo connection to that member, and I set the ReadPreference to secondary, I'm able to successfully make queries and perform other operations, but I cannot call DB.getCollectionNames(). I get the same "not talking to master and retries used up" error that happens when ReadPreference isn't set correctly. The issue appears to be here, where the ReadPreference isn't being used when querying the system.namespaces collection:

      https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/DB.java#L283

      When using slaveOk() instead, this works as expected. My understanding is that setReadPreference(SECONDARY) is supposed to behave the same way.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            robjectlabs Robert Miyashiro
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: