Method: Mongo::Operation::Aggregate::Result#documents

Defined in:
lib/mongo/operation/aggregate/result.rb

#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 '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