Class: Mongo::Operation::Commands::Aggregate::Result
- Defined in:
- lib/mongo/operation/commands/aggregate/result.rb
Overview
Defines custom behaviour of results in an aggregation context.
Constant Summary collapse
- EXPLAIN =
The field name for the aggregation explain information.
'stages'.freeze
- EXPLAIN_LEGACY =
The legacy field name for the aggregation explain information.
'serverPipeline'.freeze
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
Instance Method Summary collapse
-
#cursor_id ⇒ Integer
Get the cursor id for the result.
-
#documents ⇒ Array<BSON::Document>
Get the documents for the aggregation result.
Methods inherited from Result
#acknowledged?, #each, #initialize, #inspect, #multiple?, #namespace, #ok?, #reply, #returned_count, #successful?, #validate!, #written_count
Constructor Details
This class inherits a constructor from Mongo::Operation::Result
Instance Method Details
#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.
52 53 54 |
# File 'lib/mongo/operation/commands/aggregate/result.rb', line 52 def cursor_id cursor_document ? cursor_document[CURSOR_ID] : super 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.
67 68 69 70 |
# File 'lib/mongo/operation/commands/aggregate/result.rb', line 67 def documents reply.documents[0][RESULT] || explain_document || cursor_document[FIRST_BATCH] end |