class Mongo::Operation::Commands::ListCollections::Result

Defines custom behaviour of results when using the listCollections command.

@since 2.0.0

Public Instance Methods

cursor_id() click to toggle source

Get the cursor id for the result.

@example Get the cursor id.

result.cursor_id

@note Even though the wire protocol has a cursor_id field for all

messages of type reply, it is always zero when using the
listCollections command and must be retrieved from the cursor
document itself.

@return [ Integer ] The cursor id.

@since 2.0.0

Calls superclass method Mongo::Operation::Result#cursor_id
# File lib/mongo/operation/commands/list_collections/result.rb, line 39
def cursor_id
  cursor_document ? cursor_document[CURSOR_ID] : super
end
documents() click to toggle source

Get the documents for the listCollections result. It is the 'firstBatch'

field in the 'cursor' field of the first document returned.

@example Get the documents.

result.documents

@return [ Array<BSON::Document> ] The documents.

@since 2.0.0

# File lib/mongo/operation/commands/list_collections/result.rb, line 64
def documents
  cursor_document[FIRST_BATCH]
end
namespace() click to toggle source

Get the namespace for the cursor.

@example Get the namespace.

result.namespace

@return [ String ] The namespace.

@since 2.0.0

Calls superclass method Mongo::Operation::Result#namespace
# File lib/mongo/operation/commands/list_collections/result.rb, line 51
def namespace
  cursor_document ? cursor_document[NAMESPACE] : super
end
validate!() click to toggle source

Validate the result. In the case where an unauthorized client tries to run the command we need to generate the proper error.

@example Validate the result.

result.validate!

@return [ Result ] Self if successful.

@since 2.0.0

# File lib/mongo/operation/commands/list_collections/result.rb, line 77
def validate!
  !successful? ? raise(Error::OperationFailure.new(parser.message, self)) : self
end

Private Instance Methods

cursor_document() click to toggle source
# File lib/mongo/operation/commands/list_collections/result.rb, line 83
def cursor_document
  @cursor_document ||= first_document[CURSOR]
end
first_document() click to toggle source
# File lib/mongo/operation/commands/list_collections/result.rb, line 87
def first_document
  @first_document ||= reply.documents[0]
end