Module: Mongoid::Criteria::Queryable::Aggregable
- Extended by:
- Macroable
- Included in:
- Mongoid::Criteria::Queryable
- Defined in:
- lib/mongoid/criteria/queryable/aggregable.rb
Overview
Provides a DSL around crafting aggregation framework commands.
Instance Attribute Summary collapse
- #aggregating Flag for whether or not we are aggregating.(Flag) ⇒ Object
- #aggregating ⇒ Object writeonly
- #pipeline ⇒ Object readonly
- #pipeline The aggregation pipeline.(Theaggregationpipeline.) ⇒ Object readonly
Instance Method Summary collapse
-
#aggregating? ⇒ true, false
Has the aggregable enter an aggregation state.
-
#group(operation) ⇒ Aggregable
Add a group ($group) operation to the aggregation pipeline.
-
#project(operation = nil) ⇒ Aggregable
Add a projection ($project) to the aggregation pipeline.
-
#unwind(field) ⇒ Aggregable
Add an unwind ($unwind) to the aggregation pipeline.
Methods included from Macroable
Instance Attribute Details
#aggregating Flag for whether or not we are aggregating.(Flag) ⇒ Object
16 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 16 attr_writer :aggregating |
#aggregating=(value) ⇒ Object (writeonly)
16 17 18 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 16 def aggregating=(value) @aggregating = value end |
#pipeline ⇒ Object (readonly)
13 14 15 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 13 def pipeline @pipeline end |
#pipeline The aggregation pipeline.(Theaggregationpipeline.) ⇒ Object (readonly)
13 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 13 attr_reader :pipeline |
Instance Method Details
#aggregating? ⇒ true, false
Has the aggregable enter an aggregation state. Ie, are only aggregation operations allowed at this point on.
27 28 29 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 27 def aggregating? !!@aggregating end |
#group(operation) ⇒ Aggregable
Add a group ($group) operation to the aggregation pipeline.
44 45 46 47 48 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 44 def group(operation) aggregation(operation) do |pipeline| pipeline.group(operation) end end |
#project(operation = nil) ⇒ Aggregable
Add a projection ($project) to the aggregation pipeline.
68 69 70 71 72 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 68 def project(operation = nil) aggregation(operation) do |pipeline| pipeline.project(operation) end end |
#unwind(field) ⇒ Aggregable
Add an unwind ($unwind) to the aggregation pipeline.
84 85 86 87 88 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 84 def unwind(field) aggregation(field) do |pipeline| pipeline.unwind(field) end end |