Ensure that commands and queries set slaveOk bit and readPreference

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Critical - P2
    • 3.0.0
    • Affects Version/s: None
    • Component/s: Query Operations
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Both queries and "query-like" commands require two things to enable proper application of a non-primary read preference:

      1. set slaveOk bit if slaveOk is set (deprecated) or ReadPreference.isSlaveOk().
      2. Wrap in $query and set $readPreference field (mongos only, and only if read preference is not primary or secondaryPreferred).

      Example of an integration test that should pass:

      class CountOperationSpecification {
          def 'should run on secondary'() {
              assumeTrue(isDiscoverableReplicaSet())
      
              given:
              def find = new Find().readPreference(ReadPreference.secondary())
              def countOperation = new CountOperation(getNamespace(), find, new DocumentCodec(), bufferProvider, session, true)
      
              when:
              int count = countOperation.execute()
      
              then:
              count == 0
          }
      }
      

            Assignee:
            Unassigned
            Reporter:
            Jeffrey Yemin
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: