module Mongo::Operation::Find::Builder::Command

Builds a find command specification from options.

@api private

Constants

OPTION_MAPPINGS

The mappings from ruby options to the find command.

Public Instance Methods

convert_limit_and_batch_size!(command) click to toggle source

Converts negative limit and batchSize parameters in the find command to positive ones. Removes the parameters if their values are zero.

This is only used for find commmand, not for OP_QUERY path.

The command parameter is mutated by this method.

# File lib/mongo/operation/find/builder/command.rb, line 86
                def convert_limit_and_batch_size!(command)
  if command[:limit] && command[:limit] < 0 &&
    command[:batchSize] && command[:batchSize] < 0
  then
    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
selector(spec, connection) click to toggle source
# File lib/mongo/operation/find/builder/command.rb, line 57
                def selector(spec, connection)
  if spec[:collation] && !connection.features.collation_enabled?
    raise Error::UnsupportedCollation
  end

  BSON::Document.new.tap do |selector|
    OPTION_MAPPINGS.each do |k, server_k|
      unless (value = spec[k]).nil?
        selector[server_k] = value
      end
    end

    if rc = selector[:readConcern]
      selector[:readConcern] = Options::Mapper.transform_values_to_strings(rc)
    end

    convert_limit_and_batch_size!(selector)
  end
end