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 76
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 64
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 88
def specification
  { selector: find_command, db_name: database.name, read: read }
end

Private Instance Methods

convert_negative_limit(command) click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 100
def convert_negative_limit(command)
  if command[:limit] && command[:limit] < 0
    command.delete('limit')
    command[:singleBatch] = true
  end
  command
end
find_command() click to toggle source
# File lib/mongo/collection/view/builder/find_command.rb, line 94
def find_command
  document = BSON::Document.new('find' => collection.name, 'filter' => filter)
  command = Options::Mapper.transform_documents(options, MAPPINGS, document)
  convert_negative_limit(command)
end