sumCollection function

Future<double> sumCollection(
  1. String collectionPath,
  2. String field, {
  3. List<Where> where = const [],
  4. List<OrderBy> orderBy = const [],
  5. int? limit,
  6. int? limitToLast,
  7. bool collectionGroup = false,
})

Sums field over what a query matches, computed by the server.

Documents where the field is absent or is not a number are skipped rather than counted as zero, so a sum over a sparse field is the sum of the documents that have it.

Answers a double even when every input was an integer. Firestore returns an integer there and this widens it; rounding a sum you know is exact is better than this layer deciding which sums are safe to narrow.

Implementation

Future<double> sumCollection(
  String collectionPath,
  String field, {
  List<Where> where = const [],
  List<OrderBy> orderBy = const [],
  int? limit,
  int? limitToLast,
  bool collectionGroup = false,
}) => _aggregate(
  fdbFsSum,
  'sum',
  collectionPath,
  field,
  where: where,
  orderBy: orderBy,
  limit: limit,
  limitToLast: limitToLast,
  collectionGroup: collectionGroup,
);