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

Inherits:
Result
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/operation/aggregate/result.rb

Overview

Defines custom behavior of results in an aggregation context.

Since:

  • 2.0.0

Constant Summary collapse

EXPLAIN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The field name for the aggregation explain information.

Since:

  • 2.0.5

'stages'.freeze
EXPLAIN_LEGACY =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

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

#connection_description, #connection_global_id, #replies

Instance Method Summary collapse

Methods inherited from Result

#acknowledged?, #cluster_time, #each, #error, #has_cursor_id?, #initialize, #inspect, #labels, #namespace, #ok?, #operation_time, #reply, #returned_count, #snapshot_timestamp, #successful?, #topology_version, #validate!, #write_concern_error?, #written_count

Constructor Details

This class inherits a constructor from Mongo::Operation::Result

Instance Method Details

#cursor_idInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



54
55
56
# File 'build/ruby-driver-v2.19/lib/mongo/operation/aggregate/result.rb', line 54

def cursor_id
  cursor_document ? cursor_document[CURSOR_ID] : 0
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. Otherwise, it is an explain document.

Examples:

Get the documents.

result.documents

Returns:

  • (Array<BSON::Document>)

    The documents.

Since:

  • 2.0.0



79
80
81
82
83
84
# File 'build/ruby-driver-v2.19/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

#post_batch_resume_tokenBSON::Document | nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the post batch resume token for the result

Returns:

  • (BSON::Document | nil)

    The post batch resume token

Since:

  • 2.0.0



63
64
65
# File 'build/ruby-driver-v2.19/lib/mongo/operation/aggregate/result.rb', line 63

def post_batch_resume_token
  cursor_document ? cursor_document['postBatchResumeToken'] : nil
end