Class: Mongo::Operation::Aggregate::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/aggregate/result.rb |
Overview
Defines custom behavior of results in an aggregation context.
Constant Summary
-
EXPLAIN =
Internal use only
The field name for the aggregation explain information.
'stages'.freeze
-
EXPLAIN_LEGACY =
Internal use only
The legacy field name for the aggregation explain information.
'serverPipeline'.freeze
::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, #connection_description, #connection_global_id, #context, | |
#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
-
#cursor_id ⇒ Integer
Internal use only
Internal use only
Get the cursor id for the result.
-
#documents ⇒ Array<BSON::Document>
Get the documents for the aggregation result.
-
#post_batch_resume_token ⇒ BSON::Document | nil
Internal use only
Internal use only
Get the post batch resume token for the result.
- #cursor_document private
-
#explain_document
private
This should only be called on explain responses; it will never return a nil result and will only be meaningful on explain responses.
- #first_document private
::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 Error::OperationFailure::Family) 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 | Alias for Result#written_count. |
#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, #operation_failure_class, #parser, | |
#raise_operation_failure | Raises a Mongo::OperationFailure exception corresponding to the error information in this result. |
Instance Method Details
#cursor_document (private)
#cursor_id ⇒ Integer
Even though the wire protocol has a cursor_id field for all messages of type reply, it is always zero when using the aggregation framework and must be retrieved from the cursor document itself. Wahnsinn!
Get the cursor id for the result.
# File 'lib/mongo/operation/aggregate/result.rb', line 54
def cursor_id cursor_document ? cursor_document[CURSOR_ID] : 0 end
#documents ⇒ Array
<BSON::Document
>
Get the documents for the aggregation result. This is either the first document’s ‘result’ field, or if a cursor option was selected, it is the ‘firstBatch’ field in the ‘cursor’ field of the first document returned. Otherwise, it is an explain document.
# File 'lib/mongo/operation/aggregate/result.rb', line 79
def documents docs = reply.documents[0][RESULT] docs ||= cursor_document[FIRST_BATCH] if cursor_document docs ||= explain_document docs end
#explain_document (private)
This should only be called on explain responses; it will never return a nil result and will only be meaningful on explain responses
# File 'lib/mongo/operation/aggregate/result.rb', line 90
def explain_document first_document[EXPLAIN] || first_document[EXPLAIN_LEGACY] || [first_document] end
#first_document (private)
# File 'lib/mongo/operation/aggregate/result.rb', line 98
def first_document @first_document ||= reply.documents[0] end
#post_batch_resume_token ⇒ BSON::Document
| nil
Get the post batch resume token for the result
# File 'lib/mongo/operation/aggregate/result.rb', line 63
def post_batch_resume_token cursor_document ? cursor_document['postBatchResumeToken'] : nil end