class Mongo::Protocol::Delete::Upconverter

Converts legacy delete messages to the appropriare OP_COMMAND style message.

@since 2.1.0

Constants

DELETE

The delete command constant.

@since 2.2.0

DELETES

The deletes command constant.

@since 2.2.0

Attributes

collection[R]

@return [ String ] collection The name of the collection.

filter[R]

@return [ BSON::Document, Hash ] filter The query filter or command.

options[R]

@return [ Hash ] options The options.

Public Class Methods

new(collection, filter, options) click to toggle source

Instantiate the upconverter.

@example Instantiate the upconverter.

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

@param [ String ] collection The name of the collection. @param [ BSON::Document, Hash ] filter The filter or command.

@since 2.1.0

# File lib/mongo/protocol/delete.rb, line 133
def initialize(collection, filter, options)
  @collection = collection
  @filter = filter
  @options = options
end

Public Instance Methods

command() click to toggle source

Get the upconverted command.

@example Get the command.

upconverter.command

@return [ BSON::Document ] The upconverted command.

@since 2.1.0

# 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

Private Instance Methods

limit() click to toggle source
# File lib/mongo/protocol/delete.rb, line 157
def limit
  if options.key?(:flags)
    options[:flags].include?(:single_remove) ? 1 : 0
  else
    0
  end
end