class Moped::Protocol::Update

The Protocol class for updating documents in a collection.

@example Rename a user

Update.new "moped", "users", { _id: "123" }, { name: "Bob" }

@example Rename all users named John

Update.new "moped", "users", { name: "John" }, { name: "Bob" },
  flags: [:multi]

@example Upsert

Update.new "moped", "users", { name: "John" }, { name: "John" },
  flags: [:upsert]

@example Setting the request id

Update.new "moped", "users", {}, { name: "Bob" },
  request_id: 123

Attributes

collection[R]

@return [String, Symbol] the collection this insert targets

database[R]

@return [String, Symbol] the database this insert targets

Public Class Methods

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

Create a new update command. The database and collection arguments are joined together to set the full_collection_name.

@example

Update.new "moped", "users", { name: "John" }, { name: "Bob" },
  flags: [:upsert],
  request_id: 123

@param [String, Symbol] database the database to insert into @param [String, Symbol] collection the collection to insert into @param [Hash] selector the selector @param [Hash] update the update to perform @param [Hash] options additional options @option options [Number] :request_id the command's request id @option options [Array] :flags the flags for insertion. Supported

flags: +:upsert+, +:multi+.
# File lib/moped/protocol/update.rb, line 89
def initialize(database, collection, selector, update, options = {})
  @database = database
  @collection = collection

  @full_collection_name = "#{database}.#{collection}"
  @selector             = selector
  @update               = update
  @request_id           = options[:request_id]
  @flags                = options[:flags]
end

Public Instance Methods

log_inspect() click to toggle source
# File lib/moped/protocol/update.rb, line 100
def log_inspect
  type = "UPDATE"

  "%-12s database=%s collection=%s selector=%s update=%s flags=%s" % [type, database, collection,
                                                                      selector.inspect,
                                                                      update.inspect,
                                                                      flags.inspect]
end
op_code() click to toggle source

@return [Number] OP_UPDATE operation code (2001)

# File lib/moped/protocol/update.rb, line 63
def op_code
  2001
end