Module: Mongo::Operation::Find::Builder::Modifiers Private

Defined in:
lib/mongo/operation/find/builder/modifiers.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.

Provides behavior for mapping Ruby options to legacy OP_QUERY find modifiers.

This module is used in two ways:

  1. When Collection#find is invoked with the legacy OP_QUERY syntax (:$query argument etc.), this module is used to map the legacy parameters into the Ruby options that normally are used by applications.

  2. When sending a find operation using the OP_QUERY protocol, this module is used to map the Ruby find options to the modifiers in the wire protocol message.

Since:

  • 2.0.0

Constant Summary collapse

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

Mappings from Ruby options to OP_QUERY modifiers.

Since:

  • 2.0.0

BSON::Document.new(
  comment: '$comment',
  explain: '$explain',
  hint: '$hint',
  max_scan: '$maxScan',
  max_time_ms: '$maxTimeMS',
  max_value: '$max',
  min_value: '$min',
  return_key: '$returnKey',
  show_disk_loc: '$showDiskLoc',
  snapshot: '$snapshot',
  sort: '$orderby',
).freeze
SERVER_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.

Mappings from OP_QUERY modifiers to Ruby options.

Since:

  • 2.0.0

BSON::Document.new(DRIVER_MAPPINGS.invert).freeze

Class Method Summary collapse

Class Method Details

.map_driver_options(modifiers) ⇒ BSON::Document

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.

Transform the provided OP_QUERY modifiers to Ruby options.

Examples:

Transform to driver options.

Modifiers.map_driver_options(modifiers)

Parameters:

  • modifiers (Hash)

    The modifiers.

Returns:

  • (BSON::Document)

    The Ruby options.

Since:

  • 2.0.0



64
65
66
# File 'lib/mongo/operation/find/builder/modifiers.rb', line 64

module_function def map_driver_options(modifiers)
  Options::Mapper.transform_documents(modifiers, SERVER_MAPPINGS)
end

.map_server_modifiers(options) ⇒ BSON::Document

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.

Transform the provided Ruby options into a document of OP_QUERY modifiers.

Accepts both string and symbol keys.

The input mapping may contain additional keys that do not map to OP_QUERY modifiers, in which case the extra keys are ignored.

Examples:

Map the server modifiers.

Modifiers.map_server_modifiers(options)

Parameters:

  • options (Hash, BSON::Document)

    The options.

Returns:

  • (BSON::Document)

    The modifiers.

Since:

  • 2.0.0



82
83
84
# File 'lib/mongo/operation/find/builder/modifiers.rb', line 82

module_function def map_server_modifiers(options)
  Options::Mapper.transform_documents(options, DRIVER_MAPPINGS)
end