class Mongo::Protocol::Update

MongoDB Wire protocol Update message.

This is a client request message that is sent to the server in order to update documents matching the provided query.

The default is to update a single document. In order to update many at a time users should set the :multi_update flag for the update.

If an upsert (update or insert) is desired, users can set the :upsert flag in order to indicate they would like to insert the merged selector and update if no document matching the update query currently exists.

@api semipublic

Constants

FLAGS

Available flags for an Update message.

OP_CODE

The operation code required to specify an Update message. @return [Fixnum] the operation code.

@since 2.5.0

Attributes

upconverter[R]

Public Class Methods

new(database, collection, selector, update, options = {}) click to toggle source

Creates a new Update message

@example Update single document

Update.new('xgen', 'users', {:name => 'Tyler'}, {:name => 'Bob'})

@example Perform a multi update

Update.new('xgen', 'users',
  {:age => 20}, {:age => 21}, :flags => [:multi_update])

@example Perform an upsert

Update.new('xgen', 'users', {:name => 'Tyler'}, :flags => [:upsert])

@param database [String, Symbol] The database to update. @param collection [String, Symbol] The collection to update. @param selector [Hash] The update selector. @param update [Hash] The update to perform. @param options [Hash] The additional query options.

@option options :flags [Array] The flags for the update message.

Supported flags: +:upsert+, +:multi_update+
Calls superclass method
# File lib/mongo/protocol/update.rb, line 54
def initialize(database, collection, selector, update, options = {})
  @database    = database
  @collection  = collection
  @namespace   = "#{database}.#{collection}"
  @selector    = selector
  @update      = update
  @flags       = options[:flags] || []
  @upconverter = Upconverter.new(collection, selector, update, flags)
  super
end

Public Instance Methods

payload() click to toggle source

Return the event payload for monitoring.

@example Return the event payload.

message.payload

@return [ BSON::Document ] The event payload.

@since 2.1.0

# File lib/mongo/protocol/update.rb, line 73
def payload
  BSON::Document.new(
    command_name: 'update',
    database_name: @database,
    command: upconverter.command,
    request_id: request_id
  )
end