Module: Mongo::Operation::Find::Builder::Command Private

Defined in:
build/ruby-driver-v2.19/lib/mongo/operation/find/builder/command.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Builds a find command specification from options.

Since:

  • 2.0.0

Constant Summary collapse

OPTION_MAPPINGS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The mappings from ruby options to the find command.

Since:

  • 2.0.0

BSON::Document.new(
  allow_disk_use: 'allowDiskUse',
  allow_partial_results: 'allowPartialResults',
  await_data: 'awaitData',
  batch_size: 'batchSize',
  collation: 'collation',
  comment: 'comment',
  filter: 'filter',
  hint: 'hint',
  let: 'let',
  limit: 'limit',
  max_scan: 'maxScan',
  max_time_ms: 'maxTimeMS',
  max_value: 'max',
  min_value: 'min',
  no_cursor_timeout: 'noCursorTimeout',
  oplog_replay: 'oplogReplay',
  projection: 'projection',
  read_concern: 'readConcern',
  return_key: 'returnKey',
  show_disk_loc: 'showRecordId',
  single_batch: 'singleBatch',
  skip: 'skip',
  snapshot: 'snapshot',
  sort: 'sort',
  tailable: 'tailable',
  tailable_cursor: 'tailable',
).freeze

Class Method Summary collapse

Class Method Details

.convert_limit_and_batch_size!(command) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Since:

  • 2.0.0



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'build/ruby-driver-v2.19/lib/mongo/operation/find/builder/command.rb', line 87

module_function 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'build/ruby-driver-v2.19/lib/mongo/operation/find/builder/command.rb', line 58

module_function 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