Class: Moped::Protocol::GetMore

Inherits:
Object
  • Object
show all
Includes:
Message
Defined in:
lib/moped/protocol/get_more.rb

Overview

The Protocol class for retrieving more documents from a cursor.

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Message

included, #inspect, #serialize

Constructor Details

#initialize(database, collection, cursor_id, limit, options = {}) ⇒ GetMore

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

Examples:

Get more results using database default limit.

GetMore.new("moped", "people", 29301021, 0)

Get more results using custom limit.

GetMore.new("moped", "people", 29301021, 10)

Get more with a request id.

GetMore.new("moped", "people", 29301021, 10, request_id: 123)

Parameters:

  • database (String)

    The database name.

  • collection (String)

    The collection name.

  • cursor_id (Integer)

    The id of the cursor.

  • limit (Integer)

    The number of documents to limit.

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

    The get more options.

Options Hash (options):

  • :request_id (Integer)

    The operation’s request id.

Since:

  • 1.0.0



100
101
102
103
104
105
106
107
# File 'lib/moped/protocol/get_more.rb', line 100

def initialize(database, collection, cursor_id, limit, options = {})
  @database = database
  @collection = collection
  @full_collection_name = "#{database}.#{collection}"
  @cursor_id = cursor_id
  @limit = limit
  @request_id = options[:request_id]
end

Instance Attribute Details

#collectionString

Returns The collection to query.

Returns:

  • (String)

    The collection to query.



44
45
46
# File 'lib/moped/protocol/get_more.rb', line 44

def collection
  @collection
end

#cursor_idNumber

Returns the id of the cursor to get more documents from.

Returns:

  • (Number)

    the id of the cursor to get more documents from



36
# File 'lib/moped/protocol/get_more.rb', line 36

int64 :cursor_id

#databaseObject

Since:

  • 1.0.0



44
# File 'lib/moped/protocol/get_more.rb', line 44

attr_reader :collection, :database

#full_collection_nameString

Returns the namespaced collection name.

Returns:

  • (String)

    the namespaced collection name



28
# File 'lib/moped/protocol/get_more.rb', line 28

cstring :full_collection_name

#lengthNumber

Returns the length of the message.

Returns:

  • (Number)

    the length of the message



12
# File 'lib/moped/protocol/get_more.rb', line 12

int32 :length

#limitNumber

Returns the number of documents to return.

Returns:

  • (Number)

    the number of documents to return



32
# File 'lib/moped/protocol/get_more.rb', line 32

int32 :limit

#op_codeInteger

Get the code for a get more operation.

Examples:

Get the operation code.

get_more.op_code

Returns:

  • (Integer)

    OP_GETMORE operation code (2005).

Since:

  • 1.0.0



22
# File 'lib/moped/protocol/get_more.rb', line 22

int32 :op_code

#request_idNumber

Returns the request id of the message.

Returns:

  • (Number)

    the request id of the message



16
# File 'lib/moped/protocol/get_more.rb', line 16

int32 :request_id

Instance Method Details

#failure?(reply) ⇒ true, false

Determine if the provided reply message is a failure with respect to a get more operation.

Examples:

Is the reply a query failure?

get_more.failure?(reply)

Parameters:

  • reply (Reply)

    The reply to the get more.

Returns:

  • (true, false)

    If the reply is a failure.

Since:

  • 2.0.0



57
58
59
# File 'lib/moped/protocol/get_more.rb', line 57

def failure?(reply)
  reply.cursor_not_found? || reply.query_failure?
end

#failure_exception(reply) ⇒ Moped::Errors::CursorNotFound

Get the exception specific to a failure of this particular operation.

Examples:

Get the failure exception.

get_more.failure_exception(document)

Parameters:

Returns:

Since:

  • 2.0.0



71
72
73
74
75
76
77
# File 'lib/moped/protocol/get_more.rb', line 71

def failure_exception(reply)
  if reply.cursor_not_found?
    Errors::CursorNotFound.new(self, cursor_id)
  else
    Errors::QueryFailure.new(self, reply.documents.first)
  end
end

#log_inspectString

Provide the value that will be logged when the get more runs.

Examples:

Provide the log inspection.

get_more.log_inspect

Returns:

  • (String)

    The string value for logging.

Since:

  • 1.0.0



117
118
119
120
# File 'lib/moped/protocol/get_more.rb', line 117

def log_inspect
  type = "GET_MORE"
  "%-12s database=%s collection=%s limit=%s cursor_id=%s" % [type, database, collection, limit, cursor_id]
end

#receive_replies(connection) ⇒ Protocol::Reply

Receive replies to the message.

Examples:

Receive replies.

message.receive_replies(connection)

Parameters:

Returns:

Since:

  • 1.0.0



146
147
148
# File 'lib/moped/protocol/get_more.rb', line 146

def receive_replies(connection)
  connection.read
end

#results(reply) ⇒ Moped::Protocol::Reply

Take the provided reply and return the expected results to api consumers.

Examples:

Get the expected results of the reply.

get_more.results(reply)

Parameters:

Returns:

Since:

  • 2.0.0



161
162
163
# File 'lib/moped/protocol/get_more.rb', line 161

def results(reply)
  reply
end