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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable, Explainable, Immutable, Iterable, Loggable, Retryable
Defined in:
lib/mongo/collection/view/aggregation.rb

Overview

Provides behaviour around an aggregation pipeline on a collection view.

Since:

  • 2.0.0

Constant Summary

REROUTE =

The reroute message.

Since:

  • 2.1.0

'Rerouting the Aggregation operation to the primary server.'.freeze

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 Immutable

#options

Instance Method Summary collapse

Methods included from Retryable

#read_with_one_retry, #read_with_retry, #write_with_retry

Methods included from Loggable

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

Methods included from Iterable

#close_query, #each

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.

Since:

  • 2.0.0



73
74
75
76
77
# File 'lib/mongo/collection/view/aggregation.rb', line 73

def initialize(view, pipeline, options = {})
  @view = view
  @pipeline = pipeline.dup
  @options = BSON::Document.new(options).freeze
end

Instance Attribute Details

#pipelineArray<Hash> (readonly)

Returns pipeline The aggregation pipeline.

Returns:

  • (Array<Hash>)

    pipeline The aggregation pipeline.

Since:

  • 2.0.0



34
35
36
# File 'lib/mongo/collection/view/aggregation.rb', line 34

def pipeline
  @pipeline
end

#viewView (readonly)

Returns view The collection view.

Returns:

  • (View)

    view The collection view.

Since:

  • 2.0.0



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

def view
  @view
end

Instance Method Details

#allow_disk_use(value = nil) ⇒ true, ...

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

Examples:

Set disk usage flag.

aggregation.allow_disk_use(true)

Parameters:

  • value (true, false) (defaults to: nil)

    The flag value.

Returns:

  • (true, false, Aggregation)

    The aggregation if a value was set or the value if used as a getter.

Since:

  • 2.0.0



58
59
60
# File 'lib/mongo/collection/view/aggregation.rb', line 58

def allow_disk_use(value = nil)
  configure(:allow_disk_use, value)
end

#explainHash

Get the explain plan for the aggregation.

Examples:

Get the explain plan for the aggregation.

aggregation.explain

Returns:

  • (Hash)

    The explain plan.

Since:

  • 2.0.0



87
88
89
# File 'lib/mongo/collection/view/aggregation.rb', line 87

def explain
  self.class.new(view, pipeline, options.merge(explain: true)).first
end