streamCountWhere method

  1. @override
Stream<int> streamCountWhere(
  1. List<Clause> clauses
)
override

Gets the amount of documents from the collection, filtered by the provided clauses

Refreshes automatically when new data is added/removed from the collection

This method DOES NOT use the server side count function provided by v4.0.0 of cloud_firestore as they do not currenly support streams.

See countAll and countWhere for more details.

This method works by streaming documents from Firestore and accessing the size property once the full query is executed. This method will incur document reads and bytes transferred.

As per the Google's recommendation, you shouldn't need to worry about optimnizing for reads until it becomes a problem. Depending on the size of your app, it may never need to be optimized.

See also: streamCountAll

Implementation

@override
Stream<int> streamCountWhere(List<Clause> clauses) {
  final snapshots = ref.filter(clauses).snapshots();

  return snapshots.map((querySnapshot) => querySnapshot.size);
}