AggregateStage

class AggregateStage : Stage


Performs optionally grouped aggregation operations on the documents from previous stages.

This stage allows you to calculate aggregate values over a set of documents, optionally grouped by one or more fields or functions. You can specify:

  • Grouping Fields or Expressions: One or more fields or functions to group the documents by. For each distinct combination of values in these fields, a separate group is created. If no grouping fields are provided, a single group containing all documents is used. Not specifying groups is the same as putting the entire inputs into one group.

  • AggregateFunctions: One or more accumulation operations to perform within each group. These are defined using AliasedAggregate expressions, which are typically created by calling AggregateFunction.alias on AggregateFunction instances. Each aggregation calculates a value (e.g., sum, average, count) based on the documents within its group.

Summary

Public companion functions

AggregateStage
withAccumulators(
    accumulator: AliasedAggregate,
    vararg additionalAccumulators: AliasedAggregate
)

Create AggregateStage with one or more accumulators.

Public functions

open operator Boolean
equals(other: Any?)
open Int
AggregateStage
withGroups(group: Selectable, vararg additionalGroups: Any)

Add one or more groups to AggregateStage

AggregateStage
withGroups(groupField: String, vararg additionalGroups: Any)

Add one or more groups to AggregateStage

Inherited functions

From com.google.firebase.firestore.pipeline.Stage
AggregateStage
AggregateStage
withOption(key: String, value: Boolean)

Specify named Boolean parameter

AggregateStage
withOption(key: String, value: Double)

Specify named Double parameter

AggregateStage
withOption(key: String, value: Field)

Specify named Field parameter

AggregateStage
withOption(key: String, value: Long)

Specify named Long parameter

AggregateStage
withOption(key: String, value: String)

Specify named String parameter

Public companion functions

withAccumulators

fun withAccumulators(
    accumulator: AliasedAggregate,
    vararg additionalAccumulators: AliasedAggregate
): AggregateStage

Create AggregateStage with one or more accumulators.

Parameters
accumulator: AliasedAggregate

The first AliasedAggregate expression, wrapping an AggregateFunction with an alias for the accumulated results.

vararg additionalAccumulators: AliasedAggregate

The AliasedAggregate expressions, each wrapping an AggregateFunction with an alias for the accumulated results.

Returns
AggregateStage

AggregateStage with specified accumulators.

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

withGroups

fun withGroups(group: Selectable, vararg additionalGroups: Any): AggregateStage

Add one or more groups to AggregateStage

Parameters
group: Selectable

The Selectable expression to consider when determining group value combinations.

vararg additionalGroups: Any

The Selectable expressions to consider when determining group value combinations or Strings representing field names.

Returns
AggregateStage

AggregateStage with specified groups.

withGroups

fun withGroups(groupField: String, vararg additionalGroups: Any): AggregateStage

Add one or more groups to AggregateStage

Parameters
groupField: String

The String representing field name.

vararg additionalGroups: Any

The Selectable expressions to consider when determining group value combinations or Strings representing field names.

Returns
AggregateStage

AggregateStage with specified groups.