class Moped::Protocol::Delete

The Protocol class for deleting documents from a collection.

@example Delete all people named John

delete = Delete.new "moped", "people", { name: "John" }

@example Delete the first person named John

delete = Delete.new "moped", "people", { name: "John" },
  flags: [:remove_first]

@example Setting the request id

delete = Delete.new "moped", "people", { name: "John" },
  request_id: 123

Attributes

collection[R]

@return [String, Symbol] the collection to delete from

database[R]

@return [String, Symbol] the database to delete from

Public Class Methods

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

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

@example

Delete.new "moped", "users", { condition: true },
  flags: [:remove_first],
  request_id: 123

@param [String, Symbol] database the database to delete from @param [String, Symbol] collection the collection to delete from @param [Hash] selector the selector for which documents to delete @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: +:remove_first+
# File lib/moped/protocol/delete.rb, line 71
def initialize(database, collection, selector, options = {})
  @database   = database
  @collection = collection

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

Public Instance Methods

log_inspect() click to toggle source
# File lib/moped/protocol/delete.rb, line 87
def log_inspect
  type = "DELETE"

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

@return [Number] OP_DELETE operation code (2006)

# File lib/moped/protocol/delete.rb, line 83
def op_code
  2006
end