alexbevi
(Alex Bevilacqua)
2
Hi @Alexey_Blinov,
Specifying a Read Preference of secondaryPreferred will cause the operation to target a secondary in most situations. When combined with a maxStalenessSeconds the operation will take replication lag (“staleness”) into consideration as well.
Per your example using the Ruby driver, assuming you (a) have a secondary member available and healthy and (b) that secondary is lagging behind the primary by less than 120 seconds, the operation should target that node.
And now I’d like to check/confirm replica was used.
Assuming the operation took longer than the slow query threshold (default 100ms) you could check the mongod logs for your secondaries to confirm which node ran the query.
I tried to run explain on the result but it doesn’t provide any information like that.
The explain results should contain a serverInfo field that would tell you which server ran the operation when it was explained. This doesn’t mean the operation prior to being explained ran on this server, but assuming you used the same read preference and max staleness settings it should allow you to rule out that the operation ran on the primary.