class Mongo::Collection::View::Builder::OpQuery
Builds a legacy OP_QUERY specification from options.
@since 2.2.0
Attributes
modifiers[R]
@return [ BSON::Document ] modifiers The server modifiers.
Public Class Methods
new(view)
click to toggle source
Create the new legacy query builder.
@example Create the query builder.
QueryBuilder.new(view)
@param [ Collection::View
] view The collection view.
@since 2.2.2
# File lib/mongo/collection/view/builder/op_query.rb, line 39 def initialize(view) @view = view @modifiers = Modifiers.map_server_modifiers(options) end
Public Instance Methods
specification()
click to toggle source
# File lib/mongo/collection/view/builder/op_query.rb, line 44 def specification { :selector => requires_special_filter? ? special_filter : filter, :read => read, :options => query_options, :db_name => database.name, :coll_name => collection.name } end
Private Instance Methods
query_options()
click to toggle source
# File lib/mongo/collection/view/builder/op_query.rb, line 56 def query_options BSON::Document.new( project: options[:projection], skip: options[:skip], limit: options[:limit], flags: Flags.map_flags(options), batch_size: options[:batch_size] ) end
read_pref_formatted()
click to toggle source
# File lib/mongo/collection/view/builder/op_query.rb, line 70 def read_pref_formatted @read_formatted ||= begin if read read_pref = ServerSelector.get(read).to_mongos Mongo::Lint.validate_camel_case_read_preference(read_pref) read_pref else nil end end end
requires_special_filter?()
click to toggle source
# File lib/mongo/collection/view/builder/op_query.rb, line 66 def requires_special_filter? !modifiers.empty? || cluster.sharded? end
special_filter()
click to toggle source
# File lib/mongo/collection/view/builder/op_query.rb, line 82 def special_filter sel = BSON::Document.new(:$query => filter).merge!(modifiers) sel[:$readPreference] = read_pref_formatted unless read_pref_formatted.nil? sel end