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
18 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 18 attr_writer :aggregating |
#aggregating=(value) ⇒ Object (writeonly)
18 19 20 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 18 def aggregating=(value) @aggregating = value end |
#pipeline ⇒ Object (readonly)
15 16 17 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 15 def pipeline @pipeline end |
#pipeline The aggregation pipeline.(Theaggregationpipeline.) ⇒ Object (readonly)
15 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 15 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.
29 30 31 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 29 def aggregating? !!@aggregating end |
#group(operation) ⇒ Aggregable
Add a group ($group) operation to the aggregation pipeline.
46 47 48 49 50 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 46 def group(operation) aggregation(operation) do |pipeline| pipeline.group(operation) end end |
#project(operation = nil) ⇒ Aggregable
Add a projection ($project) to the aggregation pipeline.
70 71 72 73 74 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 70 def project(operation = nil) aggregation(operation) do |pipeline| pipeline.project(operation) end end |
#unwind(field) ⇒ Aggregable
Add an unwind ($unwind) to the aggregation pipeline.
86 87 88 89 90 |
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 86 def unwind(field) aggregation(field) do |pipeline| pipeline.unwind(field) end end |