Module: Mongoid::Criteria::Queryable::Aggregable
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Macroable
|
|
Defined in: | lib/mongoid/criteria/queryable/aggregable.rb |
Overview
Provides a DSL around crafting aggregation framework commands.
Class Method Summary
Macroable
- Extended
Instance Attribute Summary
- #aggregating Flag for whether or not we are aggregating.(Flag for whether or not we are aggregating.) rw
- #aggregating=(value) rw
-
#aggregating? ⇒ true | false
rw
Has the aggregable enter an aggregation state.
- #pipeline readonly
- #pipeline The aggregation pipeline.(The aggregation pipeline.) readonly
Instance Method Summary
-
#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.
-
#aggregation(operation) ⇒ Aggregable
private
Internal use only
Internal use only
Add the aggregation operation.
Instance Attribute Details
#aggregating Flag for whether or not we are aggregating.(Flag for whether or not we are aggregating.) (rw)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 16
attr_writer :aggregating
#aggregating=(value) (rw)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 16
attr_writer :aggregating
#aggregating? ⇒ true
| false
(rw)
Has the aggregable enter an aggregation state. Ie, are only aggregation operations allowed at this point on.
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 25
def aggregating? !!@aggregating end
#pipeline (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 13
attr_reader :pipeline
#pipeline The aggregation pipeline.(The aggregation pipeline.) (readonly)
[ GitHub ]# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 13
attr_reader :pipeline
Instance Method Details
#aggregation(operation) ⇒ Aggregable
(private)
This method is for internal use only.
Add the aggregation operation.
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 96
def aggregation(operation) return self unless operation clone.tap do |query| unless aggregating? query.pipeline.concat(query.selector.to_pipeline) query.pipeline.concat(query. .to_pipeline) query.aggregating = true end yield(query.pipeline) end end
#group(operation) ⇒ Aggregable
Add a group ($group) operation to the aggregation pipeline.
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 40
def group(operation) aggregation(operation) do |pipeline| pipeline.group(operation) end end
#project(operation = nil) ⇒ Aggregable
Add a projection ($project) to the aggregation pipeline.
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 62
def project(operation = nil) aggregation(operation) do |pipeline| pipeline.project(operation) end end
#unwind(field) ⇒ Aggregable
Add an unwind ($unwind) to the aggregation pipeline.
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 76
def unwind(field) aggregation(field) do |pipeline| pipeline.unwind(field) end end