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

Setting ReadPreference.PRIMARY on a find has no effect if slaveOk=true has been set in the connection string

      When the connection string contains slaveOk=true as an option then the following line of (groovy) code may read from a secondary server in a replica set:

      collection.findOne(new BasicDBObject([_id: key]),null, ReadPreference.PRIMARY)

      I believe that this may well affect all find methods.

      This appears to be due to the code in OutMethod.appendQuery() which ORs in Bytes.QUERYOPTION_SLAVEOK if the read preference is NOT primary but does nothing if the read preference is primary.

            Assignee:
            Unassigned Unassigned
            Reporter:
            chris@barrett-consulting.co.uk Chris Barrett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: