Class: Mongo::Protocol::Query::Upconverter

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo/protocol/query.rb

Overview

Converts legacy query messages to the appropriare OP_COMMAND style message.

Since:

  • 2.1.0

API:

  • semipublic

Constant Summary collapse

OPTION_MAPPINGS =

Mappings of the options to the find command options.

Since:

  • 2.1.0

API:

  • semipublic

{
  :project => 'projection',
  :skip => 'skip',
  :limit => 'limit',
  :batch_size => 'batchSize'
}.freeze
SPECIAL_FIELD_MAPPINGS =

Since:

  • 2.1.0

API:

  • semipublic

{
  :$readPreference => 'readPreference',
  :$orderby => 'sort',
  :$hint => 'hint',
  :$comment => 'comment',
  :$returnKey => 'returnKey',
  :$snapshot => 'snapshot',
  :$maxScan => 'maxScan',
  :$max => 'max',
  :$min => 'min',
  :$maxTimeMS => 'maxTimeMS',
  :$showDiskLoc => 'showRecordId',
  :$explain => 'explain'
}.freeze
FLAG_MAPPINGS =

Mapping of flags to find command options.

Since:

  • 2.1.0

API:

  • semipublic

{
  :tailable_cursor => 'tailable',
  :oplog_replay => 'oplogReplay',
  :no_cursor_timeout => 'noCursorTimeout',
  :await_data => 'awaitData',
  :partial => 'allowPartialResults'
}.freeze
FIND =

Find command constant.

Since:

  • 2.1.0

API:

  • semipublic

'find'.freeze
FILTER =

Filter attribute constant.

Since:

  • 2.1.0

API:

  • semipublic

'filter'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, filter, options, flags) ⇒ Upconverter

Instantiate the upconverter.

Examples:

Instantiate the upconverter.

Upconverter.new('users', { name: 'test' }, { skip: 10 })

Parameters:

  • The name of the collection.

  • The filter or command.

  • The options.

  • The flags.

Since:

  • 2.1.0

API:

  • semipublic



229
230
231
232
233
234
# File 'lib/mongo/protocol/query.rb', line 229

def initialize(collection, filter, options, flags)
  @collection = collection
  @filter = filter
  @options = options
  @flags = flags
end

Instance Attribute Details

#collectionString (readonly)

Returns collection The name of the collection.

Returns:

  • collection The name of the collection.

Since:

  • 2.1.0

API:

  • semipublic



207
208
209
# File 'lib/mongo/protocol/query.rb', line 207

def collection
  @collection
end

#filterBSON::Document, Hash (readonly)

Returns filter The query filter or command.

Returns:

  • filter The query filter or command.

Since:

  • 2.1.0

API:

  • semipublic



210
211
212
# File 'lib/mongo/protocol/query.rb', line 210

def filter
  @filter
end

#flagsArray<Symbol> (readonly)

Returns flags The flags.

Returns:

  • flags The flags.

Since:

  • 2.1.0

API:

  • semipublic



216
217
218
# File 'lib/mongo/protocol/query.rb', line 216

def flags
  @flags
end

#optionsBSON::Document, Hash (readonly)

Returns options The options.

Returns:

  • options The options.

Since:

  • 2.1.0

API:

  • semipublic



213
214
215
# File 'lib/mongo/protocol/query.rb', line 213

def options
  @options
end

Instance Method Details

#commandBSON::Document

Get the upconverted command.

Examples:

Get the command.

upconverter.command

Returns:

  • The upconverted command.

Since:

  • 2.1.0

API:

  • semipublic



244
245
246
# File 'lib/mongo/protocol/query.rb', line 244

def command
  command? ? op_command : find_command
end

#command_nameString, Symbol

Get the name of the command. If the collection is $cmd then it’s the first key in the filter, otherwise it’s a find.

Examples:

Get the command name.

upconverter.command_name

Returns:

  • The command name.

Since:

  • 2.1.0

API:

  • semipublic



257
258
259
# File 'lib/mongo/protocol/query.rb', line 257

def command_name
  (filter[:$query] || !command?) ? FIND : filter.keys.first
end