Module Origin::Aggregable
In: lib/origin/aggregable.rb

Provides a DSL around crafting aggregation framework commands.

@since 2.0.0

Methods

aggregating?   group   project   unwind  

Attributes

aggregating  [W]  @attribute [rw] aggregating Flag for whether or not we are aggregating.
pipeline  [R]  @attribute [r] pipeline The aggregation pipeline.

Public Instance methods

Has the aggregable enter an aggregation state. Ie, are only aggregation operations allowed at this point on.

@example Is the aggregable aggregating?

  aggregable.aggregating?

@return [ true, false ] If the aggregable is aggregating.

@since 2.0.0

Add a group ($group) operation to the aggregation pipeline.

@example Add a group operation being verbose.

  aggregable.group(count: { "$sum" => 1 }, max: { "$max" => "likes" })

@example Add a group operation using symbol shortcuts.

  aggregable.group(:count.sum => 1, :max.max => "likes")

@param [ Hash ] operation The group operation.

@return [ Aggregable ] The aggregable.

@since 2.0.0

Add a projection ($project) to the aggregation pipeline.

@example Add a projection to the pipeline.

  aggregable.project(author: 1, name: 0)

@param [ Hash ] criterion The projection to make.

@return [ Aggregable ] The aggregable.

@since 2.0.0

Add an unwind ($unwind) to the aggregation pipeline.

@example Add an unwind to the pipeline.

  aggregable.unwind(:field)

@param [ String, Symbol ] field The name of the field to unwind.

@return [ Aggregable ] The aggregable.

@since 2.0.0

[Validate]