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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.8.0
    • None
    • None
    • None

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: