Class: Mongo::Protocol::Reply

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

Overview

The MongoDB wire protocol message representing a reply

Examples:

socket = TCPSocket.new('localhost', 27017)
query = Protocol::Query.new('xgen', 'users', {:name => 'Tyler'})
socket.write(query)
reply = Protocol::Reply::deserialize(socket)

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 collapse

Attributes inherited from Message

#request_id

Instance Method Summary collapse

Methods inherited from Message

#==, deserialize, #hash, #initialize, #maybe_add_server_api, #maybe_compress, #maybe_decrypt, #maybe_encrypt, #maybe_inflate, #replyable?, #serialize, #set_request_id

Methods included from Id

included

Constructor Details

This class inherits a constructor from Mongo::Protocol::Message

Instance Attribute Details

#cursor_idFixnum

Returns The cursor id for this response. Will be zero if there are no additional results.

Returns:

  • (Fixnum)

    The cursor id for this response. Will be zero if there are no additional results.



103
# File 'lib/mongo/protocol/reply.rb', line 103

field :cursor_id, Int64

#documentsArray<Hash>

Returns The documents in this Reply.

Returns:

  • (Array<Hash>)

    The documents in this Reply.



115
# File 'lib/mongo/protocol/reply.rb', line 115

field :documents, Document, :@number_returned

#flagsArray<Symbol>

Returns The flags for this reply.

Supported flags: :cursor_not_found, :query_failure, :shard_config_stale, :await_capable.

Returns:

  • (Array<Symbol>)

    The flags for this reply.

    Supported flags: :cursor_not_found, :query_failure, :shard_config_stale, :await_capable



98
# File 'lib/mongo/protocol/reply.rb', line 98

field :flags, BitVector.new(FLAGS)

#number_returnedFixnum

Returns Number of documents in this Reply.

Returns:

  • (Fixnum)

    Number of documents in this Reply.



111
# File 'lib/mongo/protocol/reply.rb', line 111

field :number_returned, Int32

#starting_fromFixnum

Returns The starting position of the cursor for this Reply.

Returns:

  • (Fixnum)

    The starting position of the cursor for this Reply.



107
# File 'lib/mongo/protocol/reply.rb', line 107

field :starting_from, Int32

Instance Method Details

#cursor_not_found?true, false

Determine if the reply had a cursor not found flag.

Examples:

Did the reply have a cursor not found flag.

reply.cursor_not_found?

Returns:

  • (true, false)

    If the query cursor was not found.

Since:

  • 2.2.3



52
53
54
# File 'lib/mongo/protocol/reply.rb', line 52

def cursor_not_found?
  flags.include?(:cursor_not_found)
end

#payloadBSON::Document

Return the event payload for monitoring.

Examples:

Return the event payload.

message.payload

Returns:

  • (BSON::Document)

    The event payload.

Since:

  • 2.1.0



64
65
66
67
68
69
# File 'lib/mongo/protocol/reply.rb', line 64

def payload
  BSON::Document.new(
    reply: upconverter.command,
    request_id: request_id
  )
end

#query_failure?true, false

Determine if the reply had a query failure flag.

Examples:

Did the reply have a query failure.

reply.query_failure?

Returns:

  • (true, false)

    If the query failed.

Since:

  • 2.0.5



40
41
42
# File 'lib/mongo/protocol/reply.rb', line 40

def query_failure?
  flags.include?(:query_failure)
end