class Mongo::Collection::View::Builder::FindCommand
Builds a find command specification from options.
@since 2.2.0
Constants
- MAPPINGS
The mappings from ruby options to the find command.
@since 2.2.0
Public Class Methods
new(view, session)
click to toggle source
Create the find command builder.
@example Create the find command builder.
FindCommandBuilder.new(view)
@param [ Collection::View
] view The collection view. @param [ Session
] session The session.
@since 2.2.2
# File lib/mongo/collection/view/builder/find_command.rb, line 78 def initialize(view, session) @view = view @session = session end
Public Instance Methods
explain_specification()
click to toggle source
Get the specification for an explain command that wraps the find command.
@example Get the explain spec.
builder.explain_specification
@return [ Hash ] The specification.
@since 2.2.0
# File lib/mongo/collection/view/builder/find_command.rb, line 65 def explain_specification { selector: { explain: find_command }, db_name: database.name, read: read, session: @session } end
specification()
click to toggle source
Get the specification to pass to the find command operation.
@example Get the specification.
builder.specification
@return [ Hash ] The specification.
@since 2.2.0
# File lib/mongo/collection/view/builder/find_command.rb, line 91 def specification { selector: find_command, db_name: database.name, read: read, session: @session } end
Private Instance Methods
convert_flags(options)
click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 130 def convert_flags(options) return options if options.empty? opts = options.dup opts.delete(:cursor_type) Flags.map_flags(options).reduce(opts) do |o, key| o.merge!(key => true) end end
convert_limit_and_batch_size(command)
click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 108 def convert_limit_and_batch_size(command) if command[:limit] && command[:limit] < 0 && command[:batchSize] && command[:batchSize] < 0 command[:limit] = command[:limit].abs command[:batchSize] = command[:limit].abs command[:singleBatch] = true else [:limit, :batchSize].each do |opt| if command[opt] if command[opt] < 0 command[opt] = command[opt].abs command[:singleBatch] = true elsif command[opt] == 0 command.delete(opt) end end end end end
find_command()
click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 97 def find_command document = BSON::Document.new('find' => collection.name, 'filter' => filter) if collection.read_concern document[:readConcern] = Options::Mapper.transform_values_to_strings( collection.read_concern) end command = Options::Mapper.transform_documents(convert_flags(options), MAPPINGS, document) convert_limit_and_batch_size(command) command end