Class: Mongo::Operation::Commands::ListCollections::Result

Inherits:
Result
  • Object
show all
Defined in:
lib/mongo/operation/commands/list_collections/result.rb

Overview

Defines custom behaviour of results when using the listCollections command.

Since:

  • 2.0.0

Constant Summary

Constants inherited from Result

Result::CURSOR, Result::CURSOR_ID, Result::FIRST_BATCH, Result::N, Result::NAMESPACE, Result::NEXT_BATCH, Result::OK, Result::RESULT

Instance Attribute Summary

Attributes inherited from Result

#replies

Instance Method Summary collapse

Methods inherited from Result

#acknowledged?, #each, #initialize, #inspect, #multiple?, #ok?, #reply, #returned_count, #successful?, #written_count

Constructor Details

This class inherits a constructor from Mongo::Operation::Result

Instance Method Details

#cursor_idInteger

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.

Get the cursor id for the result.

Examples:

Get the cursor id.

result.cursor_id

Returns:

  • (Integer)

    The cursor id.

Since:

  • 2.0.0



39
40
41
# File 'lib/mongo/operation/commands/list_collections/result.rb', line 39

def cursor_id
  cursor_document ? cursor_document[CURSOR_ID] : super
end

#documentsArray<BSON::Document>

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

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

Examples:

Get the documents.

result.documents

Returns:

  • (Array<BSON::Document>)

    The documents.

Since:

  • 2.0.0



64
65
66
# File 'lib/mongo/operation/commands/list_collections/result.rb', line 64

def documents
  cursor_document[FIRST_BATCH]
end

#namespaceString

Get the namespace for the cursor.

Examples:

Get the namespace.

result.namespace

Returns:

  • (String)

    The namespace.

Since:

  • 2.0.0



51
52
53
# File 'lib/mongo/operation/commands/list_collections/result.rb', line 51

def namespace
  cursor_document ? cursor_document[NAMESPACE] : super
end

#validate!Result

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

Examples:

Validate the result.

result.validate!

Returns:

  • (Result)

    Self if successful.

Since:

  • 2.0.0



77
78
79
# File 'lib/mongo/operation/commands/list_collections/result.rb', line 77

def validate!
  !successful? ? raise(Error::OperationFailure.new(parser.message)) : self
end