Class: Mongo::Protocol::Delete

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

Overview

MongoDB Wire protocol Delete message.

This is a client request message that is sent to the server in order to delete selected documents in the specified namespace.

The operation, by default, operates on many documents. Setting the :single_remove flag allows for a single matching document to be removed.

Defined Under Namespace

Classes: Upconverter

Constant Summary

Constants inherited from Message

Message::BATCH_SIZE, Message::COLLECTION, Message::LIMIT, Message::MAX_MESSAGE_SIZE, Message::ORDERED, Message::Q

Instance Attribute Summary

Attributes inherited from Message

#request_id

Instance Method Summary collapse

Methods inherited from Message

#==, deserialize, #hash, #replyable?, #serialize, #set_request_id

Constructor Details

#initialize(database, collection, selector, options = {}) ⇒ Delete

Creates a new Delete message

Examples:

Remove all users named Tyler.

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

Parameters:

  • database (String, Symbol)

    The database to remove from.

  • collection (String, Symbol)

    The collection to remove from.

  • selector (Hash)

    The query used to select doc(s) to remove.

  • options (Hash) (defaults to: {})

    The additional delete options.

Options Hash (options):

  • :flags (Array)

    The flags for the delete message.

    Supported flags: :single_remove



43
44
45
46
47
48
49
50
# File 'lib/mongo/protocol/delete.rb', line 43

def initialize(database, collection, selector, options = {})
  @database = database
  @namespace = "#{database}.#{collection}"
  @selector = selector
  @flags = options[:flags] || []
  @upconverter = Upconverter.new(collection, selector, options)
  super
end

Instance Method Details

#payloadHash

Return the event payload for monitoring.

Examples:

Return the event payload.

message.payload

Returns:

  • (Hash)

    The event payload.

Since:

  • 2.1.0



60
61
62
63
64
65
66
67
# File 'lib/mongo/protocol/delete.rb', line 60

def payload
  {
    command_name: 'delete',
    database_name: @database,
    command: upconverter.command,
    request_id: request_id
  }
end