Class Mongo::Protocol::Update
In: lib/mongo/protocol/update.rb
Parent: Message

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

Methods

new   payload  

Classes and Modules

Class Mongo::Protocol::Update::Upconverter

Constants

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

@since 2.5.0

FLAGS = [:upsert, :multi_update]   Available flags for an Update message.

Attributes

upconverter  [R] 

Public Class methods

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+

Public Instance methods

Return the event payload for monitoring.

@example Return the event payload.

  message.payload

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

@since 2.1.0

[Validate]