module Mongo::Operation::ReadPreferenceSupported

Shared behavior of operations that support read preference.

@since 2.5.2

Constants

SLAVE_OK

Private Instance Methods

command(server) click to toggle source
Calls superclass method
# File lib/mongo/operation/shared/read_preference_supported.rb, line 51
def command(server)
  sel = super
  update_selector_for_read_pref(sel, server)
end
options(server) click to toggle source
Calls superclass method
# File lib/mongo/operation/shared/read_preference_supported.rb, line 27
def options(server)
  update_options_for_slave_ok(super, server)
end
update_options_for_slave_ok(opts, server) click to toggle source
# File lib/mongo/operation/shared/read_preference_supported.rb, line 41
def update_options_for_slave_ok(opts, server)
  if (server.cluster.single? && !server.mongos?) || (read && read.slave_ok?)
    opts.dup.tap do |o|
      (o[:flags] ||= []) << SLAVE_OK
    end
  else
    opts
  end
end
update_selector_for_read_pref(sel, server) click to toggle source
# File lib/mongo/operation/shared/read_preference_supported.rb, line 31
def update_selector_for_read_pref(sel, server)
  if read && server.mongos? && read_pref = read.to_mongos
    Mongo::Lint.validate_camel_case_read_preference(read_pref)
    sel = sel[:$query] ? sel : {:$query => sel}
    sel = sel.merge(:$readPreference => read_pref)
  else
    sel
  end
end