Class: Mongo::Collection::View::Aggregation
- Inherits:
-
Object
- Object
- Mongo::Collection::View::Aggregation
- Extended by:
- Forwardable
- Includes:
- Enumerable, Explainable, Immutable, Iterable, Loggable, Retryable
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb
Overview
Provides behavior around an aggregation pipeline on a collection view.
Direct Known Subclasses
Constant Summary collapse
- REROUTE =
Deprecated.
The reroute message.
'Rerouting the Aggregation operation to the primary server.'.freeze
Constants included from Loggable
Constants included from Explainable
Explainable::ALL_PLANS_EXECUTION, Explainable::EXECUTION_STATS, Explainable::QUERY_PLANNER
Instance Attribute Summary collapse
-
#pipeline ⇒ Array<Hash>
readonly
Pipeline The aggregation pipeline.
-
#view ⇒ View
readonly
View The collection view.
Attributes included from Iterable
Attributes included from Immutable
Instance Method Summary collapse
-
#allow_disk_use(value = nil) ⇒ true, ...
Set to true if disk usage is allowed during the aggregation.
-
#explain ⇒ Hash
Get the explain plan for the aggregation.
-
#initialize(view, pipeline, options = {}) ⇒ Aggregation
constructor
Initialize the aggregation for the provided collection view, pipeline and options.
-
#write? ⇒ Boolean
private
Whether this aggregation will write its result to a database collection.
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
Constructor Details
#initialize(view, pipeline, options = {}) ⇒ Aggregation
Initialize the aggregation for the provided collection view, pipeline and options.
97 98 99 100 101 102 103 104 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb', line 97 def initialize(view, pipeline, = {}) @view = view @pipeline = pipeline.dup unless Mongo.broken_view_aggregate || view.filter.empty? @pipeline.unshift(:$match => view.filter) end @options = BSON::Document.new().freeze end |
Instance Attribute Details
#pipeline ⇒ Array<Hash> (readonly)
Returns pipeline The aggregation pipeline.
37 38 39 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb', line 37 def pipeline @pipeline end |
#view ⇒ View (readonly)
Returns view The collection view.
35 36 37 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb', line 35 def view @view end |
Instance Method Details
#allow_disk_use(value = nil) ⇒ true, ...
Set to true if disk usage is allowed during the aggregation.
62 63 64 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb', line 62 def allow_disk_use(value = nil) configure(:allow_disk_use, value) end |
#explain ⇒ Hash
Get the explain plan for the aggregation.
114 115 116 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb', line 114 def explain self.class.new(view, pipeline, .merge(explain: true)).first 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.
124 125 126 |
# File 'build/ruby-driver-v2.19/lib/mongo/collection/view/aggregation.rb', line 124 def write? pipeline.any? { |op| op.key?('$out') || op.key?(:$out) || op.key?('$merge') || op.key?(:$merge) } end |