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
Source
# File lib/mongo/collection/view/builder/find_command.rb, line 64 def initialize(view, session) @view = view @session = session end
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
Public Instance Methods
Source
# File lib/mongo/collection/view/builder/find_command.rb, line 97 def explain_specification { selector: { explain: find_command, }, db_name: database.name, read: read, session: @session, # We should always have options{:explain] set if we are explaining. # The explain field is not sent to the server, it will be # processed in the operation layer. explain: options[:explain], } end
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
Source
# File lib/mongo/collection/view/builder/find_command.rb, line 79 def specification { selector: find_command, db_name: database.name, read: read, session: @session, } end
Get the specification to pass to the find command operation.
@example Get the specification.
builder.specification
@return [ Hash ] The specification.
@since 2.2.0
Private Instance Methods
Source
# File lib/mongo/collection/view/builder/find_command.rb, line 154 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
Source
# File lib/mongo/collection/view/builder/find_command.rb, line 132 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
Source
# File lib/mongo/collection/view/builder/find_command.rb, line 114 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) if command['oplogReplay'] log_warn("oplogReplay is deprecated and ignored by MongoDB 4.4 and later") end convert_limit_and_batch_size(command) command end
Source
# File lib/mongo/collection/view/builder/find_command.rb, line 163 def log_warn(*args) database.client.log_warn(*args) end