AggregateField class abstract

Represents an aggregation that can be performed by Firestore.

Create instances with AggregateField.count, AggregateField.sum and AggregateField.average and pass them to Query.aggregate.

final Query<Map<String, Object?>> orders = firestore
    .collection('orders')
    .where('status', isEqualTo: 'paid');
final AggregateQuerySnapshot result = await orders.aggregate(
  <AggregateField>[
    AggregateField.count(),
    AggregateField.sum('total'),
    AggregateField.average('total'),
  ],
).get();
final int? count = result.count;
final num? sum = result.getSum('total');
final double? average = result.getAverage('total');

Aggregations are computed by the server over the documents that match the query, without downloading them; they are not available offline. Two aggregate fields are equal when they have the same operator and field, so you can pass a new AggregateField.sum('total') to read a result. These are the JS SDK's count(), sum() and average().

Properties

fieldPath → String
The canonical string of the field this aggregation operates on, or the empty string for aggregations without a field (count).
no setter
hashCode → int
The hash code for this object.
no setteroverride
operator → String
The name of the aggregation operator: count, sum or average.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
override

Static Methods

average(Object field) → AverageAggregateField
Creates an AggregateField that averages the values of field over the documents in the result set. The result is a double, or null if no document has a numeric value for the field.
count() → CountAggregateField
Creates an AggregateField that counts the documents in the result set.
sum(Object field) → SumAggregateField
Creates an AggregateField that sums the values of field over the documents in the result set.