module Mongo::Operation::ReadPreference
Adds behaviour for updating the options and the selector for operations that need to take read preference into account.
@since 2.0.0
Constants
- SLAVE_OK
The constant for slave ok flags.
@since 2.0.6
Private Instance Methods
message(context)
click to toggle source
# File lib/mongo/operation/read_preference.rb, line 54 def message(context) sel = update_selector(context) opts = update_options(context) Protocol::Query.new(db_name, query_coll, sel, opts) end
slave_ok?(context)
click to toggle source
# File lib/mongo/operation/read_preference.rb, line 40 def slave_ok?(context) (context.cluster.single? && !context.mongos?) || read.slave_ok? end
update_options(context)
click to toggle source
# File lib/mongo/operation/read_preference.rb, line 44 def update_options(context) if slave_ok?(context) options.dup.tap do |opts| (opts[:flags] ||= []) << SLAVE_OK end else options end end
update_selector(context)
click to toggle source
# File lib/mongo/operation/read_preference.rb, line 31 def update_selector(context) if context.mongos? && read_pref = read.to_mongos sel = selector[:$query] ? selector : { :$query => selector } sel.merge(:$readPreference => read_pref) else selector end end