Class: Mongo::Protocol::Update::Upconverter

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

Overview

Converts legacy update messages to the appropriare OP_COMMAND style message.

Since:

  • 2.1.0

Constant Summary

MULTI =

The multi constant.

Since:

  • 2.2.0

'multi'.freeze
U =

The u constant.

Since:

  • 2.2.0

'u'.freeze
UPDATE =

The update constant.

Since:

  • 2.2.0

'update'.freeze
UPDATES =

The updates constant.

Since:

  • 2.2.0

'updates'.freeze
UPSERT =

The upsert constant.

Since:

  • 2.2.0

'upsert'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Instantiate the upconverter.

Examples:

Instantiate the upconverter.

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

Parameters:

  • collection (String)

    The name of the collection.

  • filter (Hash)

    The filter.

  • update (Hash)

    The update.

  • flags (Array<Symbol>)

    The flags.

Since:

  • 2.1.0



175
176
177
178
179
180
# File 'lib/mongo/protocol/update.rb', line 175

def initialize(collection, filter, update, flags)
  @collection = collection
  @filter = filter
  @update = update
  @flags = flags
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



148
149
150
# File 'lib/mongo/protocol/update.rb', line 148

def collection
  @collection
end

#filterHash (readonly)

Returns filter The filter.

Returns:

  • (Hash)

    filter The filter.

Since:

  • 2.1.0



151
152
153
# File 'lib/mongo/protocol/update.rb', line 151

def filter
  @filter
end

#flagsArray<Symbol> (readonly)

Returns flags The flags.

Returns:

  • (Array<Symbol>)

    flags The flags.

Since:

  • 2.1.0



157
158
159
# File 'lib/mongo/protocol/update.rb', line 157

def flags
  @flags
end

#updateHash (readonly)

Returns update The update.

Returns:

  • (Hash)

    update The update.

Since:

  • 2.1.0



154
155
156
# File 'lib/mongo/protocol/update.rb', line 154

def update
  @update
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



190
191
192
193
194
195
196
197
198
199
200
201
# 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)
  updates.store(MULTI, flags.include?(:multi_update))
  updates.store(UPSERT, flags.include?(:upsert))
  document.store(UPDATE, collection)
  document.store(Message::ORDERED, true)
  document.store(UPDATES, [ updates ])
  document
end