Module: Mongo::Collection::View::Aggregation::Behavior

Extended by:
Forwardable
Includes:
Enumerable, Explainable, Immutable, Iterable, Loggable, Retryable
Included in:
Mongo::Collection::View::Aggregation, ChangeStream
Defined in:
lib/mongo/collection/view/aggregation/behavior.rb

Overview

Distills the behavior common to aggregator classes, like View::Aggregator and View::ChangeStream.

Since:

  • 2.0.0

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 Mongo::CursorHost

#cursor, #timeout_mode

Attributes included from Immutable

#options

Instance Method Summary collapse

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 Iterable

#close_query, #each

Methods included from Mongo::CursorHost

#validate_timeout_mode!

Instance Attribute Details

#viewView (readonly)

Returns view The collection view.

Returns:

  • (View)

    view The collection view.

Since:

  • 2.0.0



19
20
21
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 19

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



38
39
40
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 38

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



50
51
52
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 50

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

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

Returns the timeout_ms value that was passed as an option to this object, or which was inherited from the view.

Returns:

  • (Integer | nil)

    the timeout_ms value that was passed as an option to this object, or which was inherited from the view.

Since:

  • 2.0.0



68
69
70
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 68

def timeout_ms
  @timeout_ms || view.timeout_ms
end

#write?Boolean

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.

Whether this aggregation will write its result to a database collection.

Returns:

  • (Boolean)

    Whether the aggregation will write its result to a collection.

Since:

  • 2.0.0



60
61
62
# File 'lib/mongo/collection/view/aggregation/behavior.rb', line 60

def write?
  pipeline.any? { |op| op.key?('$out') || op.key?(:$out) || op.key?('$merge') || op.key?(:$merge) }
end