Class: Mongo::Operation::Commands::ListIndexes::Result

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

Overview

Defines custom behaviour of results when using the listIndexes 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 listIndexes 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_indexes/result.rb', line 39

def cursor_id
  cursor_document ? cursor_document[CURSOR_ID] : super
end

#documentsArray<BSON::Document>

Get the documents for the listIndexes result. This 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_indexes/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_indexes/result.rb', line 51

def namespace
  cursor_document ? cursor_document[NAMESPACE] : super
end

#validate!Result

Validate the result. In the case where the database or collection does not exist on the server we will get an error, and it's better to raise a meaningful exception here than the ambiguous one when the error occurs.

Examples:

Validate the result.

result.validate!

Returns:

  • (Result)

    Self if successful.

Raises:

  • (NoNamespace)

    If the ns doesn't exist.

Since:

  • 2.0.0



81
82
83
# File 'lib/mongo/operation/commands/list_indexes/result.rb', line 81

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