class Mongo::Protocol::Update::Upconverter

Converts legacy update messages to the appropriare OP_COMMAND style message.

@since 2.1.0

Constants

MULTI

The multi constant.

@since 2.2.0

U

The u constant.

@since 2.2.0

UPDATE

The update constant.

@since 2.2.0

UPDATES

The updates constant.

@since 2.2.0

UPSERT

The upsert constant.

@since 2.2.0

Attributes

collection[R]

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

filter[R]

@return [ Hash ] filter The filter.

flags[R]

@return [ Array<Symbol> ] flags The flags.

update[R]

@return [ Hash ] update The update.

Public Class Methods

new(collection, filter, update, flags) click to toggle source

Instantiate the upconverter.

@example Instantiate the upconverter.

Upconverter.new(
  'users',
  { name: 'test' },
  { '$set' => { 'name' => 't' }},
  []
)

@param [ String ] collection The name of the collection. @param [ Hash ] filter The filter. @param [ Hash ] update The update. @param [ Array<Symbol> ] flags The flags.

@since 2.1.0

# File lib/mongo/protocol/update.rb, line 175
def initialize(collection, filter, update, flags)
  @collection = collection
  @filter = filter
  @update = update
  @flags = flags
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/update.rb, line 190
def command
  document = BSON::Document.new
  updates = BSON::Document.new
  updates.store(Message::Q, filter)
  updates.store(U, update)
  if flags.include?(:multi_update)
    updates.store(MULTI, true)
  end
  if flags.include?(:upsert)
    updates.store(UPSERT, true)
  end
  document.store(UPDATE, collection)
  document.store(Message::ORDERED, true)
  document.store(UPDATES, [ updates ])
  document
end