Class: Mongo::Collection::View::Aggregation

Inherits:
Object
  • Object
show all
Includes:
Behavior
Defined in:
lib/mongo/collection/view/aggregation.rb,
lib/mongo/collection/view/aggregation/behavior.rb

Overview

Provides behavior around an aggregation pipeline on a collection view.

Since:

  • 2.0.0

Direct Known Subclasses

ChangeStream

Defined Under Namespace

Modules: Behavior

Constant Summary

Constants included from Loggable

Loggable::PREFIX

Constants included from Explainable

Explainable::ALL_PLANS_EXECUTION, Explainable::EXECUTION_STATS, Explainable::QUERY_PLANNER

Instance Attribute Summary collapse

Attributes included from Behavior

#view

Attributes included from Mongo::CursorHost

#cursor, #timeout_mode

Attributes included from Immutable

#options

Instance Method Summary collapse

Methods included from Behavior

#allow_disk_use, #explain, #timeout_ms, #write?

Methods included from Retryable

#read_worker, #select_server, #write_worker

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger

Methods included from Explainable

#explain

Methods included from Iterable

#close_query, #each

Methods included from Mongo::CursorHost

#validate_timeout_mode!

Constructor Details

#initialize(view, pipeline, options = {}) ⇒ Aggregation

Initialize the aggregation for the provided collection view, pipeline and options.

Examples:

Create the new aggregation view.

Aggregation.view.new(view, pipeline)

Parameters:

  • view (Collection::View)

    The collection view.

  • pipeline (Array<Hash>)

    The pipeline of operations.

  • options (Hash) (defaults to: {})

    The aggregation options.

Options Hash (options):

  • :allow_disk_use (true, false)

    Set to true if disk usage is allowed during the aggregation.

  • :batch_size (Integer)

    The number of documents to return per batch.

  • :bypass_document_validation (true, false)

    Whether or not to skip document level validation.

  • :collation (Hash)

    The collation to use.

  • :comment (Object)

    A user-provided comment to attach to this command.

  • :hint (String)

    The index to use for the aggregation.

  • :let (Hash)

    Mapping of variables to use in the pipeline. See the server documentation for details.

  • :max_time_ms (Integer)

    The maximum amount of time in milliseconds to allow the aggregation to run. This option is deprecated, use :timeout_ms instead.

  • :session (Session)

    The session to use.

  • :timeout_mode (:cursor_lifetime | :iteration)

    How to interpret :timeout_ms (whether it applies to the lifetime of the cursor, or per iteration).

  • :timeout_ms (Integer)

    The operation timeout in milliseconds. Must be a non-negative integer. An explicit value of 0 means infinite. The default value is unset which means the value is inherited from the collection or the database or the client.

Since:

  • 2.0.0



68
69
70
71
72
73
74
75
# File 'lib/mongo/collection/view/aggregation.rb', line 68

def initialize(view, pipeline, options = {})
  perform_setup(view, options) do
    @pipeline = pipeline.dup
    unless Mongo.broken_view_aggregate || view.filter.empty?
      @pipeline.unshift(:$match => view.filter)
    end
  end
end

Instance Attribute Details

#pipelineArray<Hash> (readonly)

Returns pipeline The aggregation pipeline.

Returns:

  • (Array<Hash>)

    pipeline The aggregation pipeline.

Since:

  • 2.0.0



31
32
33
# File 'lib/mongo/collection/view/aggregation.rb', line 31

def pipeline
  @pipeline
end