123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Operation::Indexes::Result

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, ::Mongo::Operation::Result, Forwardable
Instance Chain:
self, ::Mongo::Operation::Result, Enumerable
Inherits: Mongo::Operation::Result
Defined in: lib/mongo/operation/indexes/result.rb

Overview

Defines custom behavior of results when using the listIndexes command.

Since:

  • 2.0.0

Constant Summary

::Mongo::Operation::Result - Inherited

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

Class Method Summary

::Mongo::Operation::Result - Inherited

.new

Initialize a new result.

Instance Attribute Summary

::Mongo::Operation::Result - Inherited

#acknowledged?

Is the result acknowledged?

#connection_description, #connection_global_id,
#has_cursor_id?

Whether the result contains cursor_id.

#ok?

Check the first document’s ok field.

#replies,
#successful?

If the result was a command then determine if it was considered a success.

#write_concern_error?

Whether the operation failed with a write concern error.

#query_failure?

Instance Method Summary

::Mongo::Operation::Result - Inherited

#cluster_time

Get the cluster time reported in the server response.

#cursor_id

Get the cursor id if the response is acknowledged.

#documents

Get the documents in the result.

#each

Iterate over the documents in the replies.

#error

The exception instance (of the ::Mongo::Error::OperationFailure class) that would be raised during processing of this result.

#inspect

Get the pretty formatted inspection of the result.

#labels

Gets the set of error labels associated with the result.

#n
#namespace

Get the namespace of the cursor.

#operation_time

Get the operation time reported in the server response.

#reply

Get the reply from the result.

#returned_count

Get the number of documents returned by the server in this batch.

#snapshot_timestamp, #topology_version,
#validate!

Validate the result by checking for any errors.

#written_count

Get the number of documents written by the server.

#aggregate_returned_count, #aggregate_written_count, #first_document, #parser,
#raise_operation_failure

Raises a Mongo::OperationFailure exception corresponding to the error information in this result.

Instance Method Details

#cursor_document (private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/operation/indexes/result.rb', line 94

def cursor_document
  @cursor_document ||= first_document[CURSOR]
end

#cursor_idInteger

This method is for internal use only.
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

[ GitHub ]

  
# File 'lib/mongo/operation/indexes/result.rb', line 43

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

[ GitHub ]

  
# File 'lib/mongo/operation/indexes/result.rb', line 70

def documents
  cursor_document[FIRST_BATCH]
end

#first_document (private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/operation/indexes/result.rb', line 98

def first_document
  @first_document ||= reply.documents[0]
end

#namespaceString

This method is for internal use only.

Get the namespace for the cursor.

Examples:

Get the namespace.

result.namespace

Returns:

  • (String)

    The namespace.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/operation/indexes/result.rb', line 56

def namespace
  cursor_document ? cursor_document[NAMESPACE] : super
end

#validate!Result

This method is for internal use only.

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

[ GitHub ]

  
# File 'lib/mongo/operation/indexes/result.rb', line 88

def validate!
  !successful? ? raise_operation_failure : self
end