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) 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.

@since 2.2.2

# File lib/mongo/collection/view/builder/find_command.rb, line 77
def initialize(view)
  @view = view
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 }
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 89
def specification
  { selector: find_command, db_name: database.name, read: read }
end

Private Instance Methods

convert_flags(options) click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 109
def convert_flags(options)
  return options if options.empty?
  opts = options.dup
  opts.delete(:cursor_type)
  Flags.map_flags(options).reduce(opts) do |opts, key|
    opts.merge!(key => true)
  end
end
convert_negative_limit(command) click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 101
def convert_negative_limit(command)
  if command[:limit] && command[:limit] < 0
    command['limit'] = command['limit'].abs
    command[:singleBatch] = true
  end
  command
end
find_command() click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 95
def find_command
  document = BSON::Document.new('find' => collection.name, 'filter' => filter)
  command = Options::Mapper.transform_documents(convert_flags(options), MAPPINGS, document)
  convert_negative_limit(command)
end