Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1132

count / distinct doesn't apply read preference

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.3.0
    • Affects Version/s: 2.2.5
    • Component/s: Server Selection
    • None

      I just noticed that the read preference doesn't seem to be applied to some commands like count and distinct and probably others.

      Here is an example from our production database:

      Mongoid.default_client.with(read: {mode: :secondary})['domains'].count
      DEBUG -- : MONGODB | 10.10.11.7:27017 | db.count | STARTED | {"count"=>"domains", "query"=>{}}
      DEBUG -- : MONGODB | 10.10.11.7:27017 | db.count | SUCCEEDED | 0.00042349900000000003s
      
      Mongoid.default_client.with(read: {mode: :secondary})['domains'].find.each {}
      DEBUG -- : MONGODB | 10.10.11.8:27017 | db.find | STARTED | {"find"=>"domains", "filter"=>{}}
      DEBUG -- : MONGODB | 10.10.11.8:27017 | db.find | SUCCEEDED | 0.039891065s
      

      10.10.11.7 is primary
      10.10.11.8 is secondary

      I also tried with

      .count(read: {mode: :secondary})
      

      as I saw RUBY-850 but it doesn't work either.

      I noticed SERVER-22043 talking about the same kind of issue in the CLI, and it was fixed by using runReadCommand instead of runCommand I don't know if it has anything to do here but maybe.

      Also, I couldn't find any info about .with() in Mongoid doc and used the mongo ruby doc instead, maybe you should add a few lines about it.

            Assignee:
            Unassigned Unassigned
            Reporter:
            bigbourin@gmail.com Adrien Jarthon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: