class Mongo::Operation::Indexes::Result
Defines custom behavior of results when using the listIndexes command.
@since 2.0.0
Public Instance Methods
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 listIndexes command and must be retrieved from the cursor document itself.
@return [ Integer ] The cursor id.
@since 2.0.0
Mongo::Operation::Result#cursor_id
# File lib/mongo/operation/indexes/result.rb, line 38 def cursor_id cursor_document ? cursor_document[CURSOR_ID] : super end
Get the documents for the listIndexes result. This 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/indexes/result.rb, line 63 def documents cursor_document[FIRST_BATCH] end
Get the namespace for the cursor.
@example Get the namespace.
result.namespace
@return [ String ] The namespace.
@since 2.0.0
Mongo::Operation::Result#namespace
# File lib/mongo/operation/indexes/result.rb, line 50 def namespace cursor_document ? cursor_document[NAMESPACE] : super end
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.
@example Validate the result.
result.validate!
@raise [ NoNamespace ] If the ns doesn't exist.
@return [ Result
] Self if successful.
@since 2.0.0
# File lib/mongo/operation/indexes/result.rb, line 80 def validate! !successful? ? raise_operation_failure : self end
Private Instance Methods
# File lib/mongo/operation/indexes/result.rb, line 86 def cursor_document @cursor_document ||= first_document[CURSOR] end
# File lib/mongo/operation/indexes/result.rb, line 90 def first_document @first_document ||= reply.documents[0] end