module Mongoid::Criteria::Queryable::Aggregable

def aggregating?

Returns:
  • (true | false) - If the aggregable is aggregating.

Other tags:
    Example: Is the aggregable aggregating? -
def aggregating?
  !!@aggregating
end

def aggregation(operation)

Returns:
  • (Aggregable) - The cloned aggregable.

Parameters:
  • operation (Hash) -- The operation for the pipeline.

Other tags:
    Example: Aggregate on the operation. -

Other tags:
    Api: - private
def aggregation(operation)
  return self unless operation
  clone.tap do |query|
    unless aggregating?
      query.pipeline.concat(query.selector.to_pipeline)
      query.pipeline.concat(query.options.to_pipeline)
      query.aggregating = true
    end
    yield(query.pipeline)
  end
end

def group(operation)

Returns:
  • (Aggregable) - The aggregable.

Parameters:
  • operation (Hash) -- The group operation.

Other tags:
    Example: Add a group operation using symbol shortcuts. -
    Example: Add a group operation being verbose. -
def group(operation)
  aggregation(operation) do |pipeline|
    pipeline.group(operation)
  end
end

def project(operation = nil)

Returns:
  • (Aggregable) - The aggregable.

Parameters:
  • operation (Hash) -- The projection to make.

Other tags:
    Example: Add a projection to the pipeline. -
def project(operation = nil)
  aggregation(operation) do |pipeline|
    pipeline.project(operation)
  end
end

def unwind(field)

Returns:
  • (Aggregable) - The aggregable.

Parameters:
  • field (String | Symbol) -- The name of the field to unwind.

Other tags:
    Example: Add an unwind to the pipeline. -
def unwind(field)
  aggregation(field) do |pipeline|
    pipeline.unwind(field)
  end
end