123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Protocol::Reply

Relationships & Source Files
Namespace Children
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Message
Instance Chain:
Inherits: Mongo::Protocol::Message
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)

Constant Summary

Serializers - Included

HEADER_PACK, INT32_PACK, INT64_PACK, NULL, ZERO

Message - Inherited

BATCH_SIZE, COLLECTION, LIMIT, MAX_MESSAGE_SIZE, ORDERED, Q

Class Method Summary

Message - Inherited

.deserialize

Deserializes messages from an IO stream.

.new

:nodoc:

.deserialize_array

Deserializes an array of fields in a message.

.deserialize_field

Deserializes a single field in a message.

.deserialize_header

Deserializes the header of the message.

.field

A method for declaring a message field.

.fields

A class method for getting the fields for a message class.

Instance Attribute Summary

Message - Inherited

#replyable?

The default for messages is not to require a reply after sending a message to the server.

#request_id

Returns the request id for the message.

Instance Method Summary

Message - Inherited

#==

Tests for equality between two wire protocol messages by comparing class and field values.

#eql?

Alias for Message#==.

#hash

Creates a hash from the values of the fields of a message.

#maybe_add_server_api,
#maybe_compress

Compress the message, if supported by the wire protocol used and if the command being sent permits compression.

#maybe_decrypt

Possibly decrypt this message with libmongocrypt.

#maybe_encrypt

Possibly encrypt this message with libmongocrypt.

#maybe_inflate

Inflate a message if it is compressed.

#number_returned

Default number returned value for protocol messages.

#serialize

Serializes message into bytes that can be sent on the wire.

#set_request_id

Generates a request id for a message.

#to_s
#compress_if_possible

Compress the message, if the command being sent permits compression.

#fields

A method for getting the fields for a message class.

#merge_sections,
#serialize_fields

Serializes message fields into a buffer.

#serialize_header

Serializes the header of the message consisting of 4 32bit integers.

Constructor Details

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

Instance Attribute Details

#cursor_idFixnum (rw)

Returns:

  • (Fixnum)

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

[ GitHub ]

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

field :cursor_id, Int64

#cursor_not_found?true, false (readonly)

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

[ GitHub ]

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

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

#documentsArray<Hash> (rw)

Returns:

  • (Array<Hash>)

    The documents in this Reply.

[ GitHub ]

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

field :documents, Document, :@number_returned

#flagsArray<Symbol> (rw)

Returns:

  • (Array<Symbol>)

    The flags for this reply.

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

[ GitHub ]

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

field :flags, BitVector.new(FLAGS)

#number_returnedFixnum (rw)

Returns:

  • (Fixnum)

    Number of documents in this Reply.

[ GitHub ]

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

field :number_returned, Int32

#query_failure?true, false (readonly)

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

[ GitHub ]

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

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

#starting_fromFixnum (rw)

Returns:

  • (Fixnum)

    The starting position of the cursor for this Reply.

[ GitHub ]

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

field :starting_from, Int32

Instance Method Details

#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

[ GitHub ]

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

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

#upconverter (private)

[ GitHub ]

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

def upconverter
  @upconverter ||= Upconverter.new(documents, cursor_id, starting_from)
end