Details
-
Bug
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
2.2.5
-
None
Description
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.