countAll method

  1. @override
Future<int> countAll()
override

Gets the amount of all documents within the collection.

Uses the count feature introduced in v4.0.0 of cloud_firestore to count documents on the server without retrieving documents.

Firestore Release Notes

Cloud Firestore now supports a count() aggregation query that allows you to determine the number of documents in a collection. The server calculates the count, and transmits only the result, a single integer, back to your app, saving on both billed document reads and bytes transferred, compared to executing the full query.

Source: https://firebase.google.com/support/releases#firestore-count-queries

See also: countWhere

Implementation

@override
Future<int> countAll() async {
  final snapshot = await untypedRef.count().get();

  return snapshot.count ?? 0;
}