Class: Mongo::Protocol::Delete::Upconverter

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

Overview

Converts legacy delete messages to the appropriare OP_COMMAND style message.

Since:

  • 2.1.0

Constant Summary

DELETE =

The delete command constant.

Since:

  • 2.2.0

'delete'.freeze
DELETES =

The deletes command constant.

Since:

  • 2.2.0

'deletes'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, filter, options) ⇒ Upconverter

Instantiate the upconverter.

Examples:

Instantiate the upconverter.

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

Parameters:

  • collection (String)

    The name of the collection.

  • filter (BSON::Document, Hash)

    The filter or command.

Since:

  • 2.1.0



133
134
135
136
137
# File 'lib/mongo/protocol/delete.rb', line 133

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

Instance Attribute Details

#collectionString (readonly)

Returns collection The name of the collection.

Returns:

  • (String)

    collection The name of the collection.

Since:

  • 2.1.0



116
117
118
# File 'lib/mongo/protocol/delete.rb', line 116

def collection
  @collection
end

#filterBSON::Document, Hash (readonly)

Returns filter The query filter or command.

Returns:

  • (BSON::Document, Hash)

    filter The query filter or command.

Since:

  • 2.1.0



119
120
121
# File 'lib/mongo/protocol/delete.rb', line 119

def filter
  @filter
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.1.0



122
123
124
# File 'lib/mongo/protocol/delete.rb', line 122

def options
  @options
end

Instance Method Details

#commandBSON::Document

Get the upconverted command.

Examples:

Get the command.

upconverter.command

Returns:

  • (BSON::Document)

    The upconverted command.

Since:

  • 2.1.0



147
148
149
150
151
152
153
# File 'lib/mongo/protocol/delete.rb', line 147

def command
  document = BSON::Document.new
  document.store(DELETE, collection)
  document.store(DELETES, [ BSON::Document.new(Message::Q => filter, Message::LIMIT => limit) ])
  document.store(Message::ORDERED, true)
  document
end