Class: Mongo::Operation::Commands::Aggregate::Result

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

Overview

Defines custom behaviour of results in an aggregation context.

Since:

  • 2.0.0

Constant Summary

EXPLAIN =

The field name for the aggregation explain information.

Since:

  • 2.0.5

'stages'.freeze
EXPLAIN_LEGACY =

The legacy field name for the aggregation explain information.

Since:

  • 2.0.5

'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

#replies

Instance Method Summary collapse

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_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 aggregation framework and must be retrieved from the cursor document itself. Wahnsinn!

Get the cursor id for the result.

Examples:

Get the cursor id.

result.cursor_id

Returns:

  • (Integer)

    The cursor id.

Since:

  • 2.0.0



52
53
54
# File 'lib/mongo/operation/commands/aggregate/result.rb', line 52

def cursor_id
  cursor_document ? cursor_document[CURSOR_ID] : super
end

#documentsArray<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.

Examples:

Get the documents.

result.documents

Returns:

  • (Array<BSON::Document>)

    The documents.

Since:

  • 2.0.0



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