count<T extends YustDoc> method

Future<int> count<T extends YustDoc>(
  1. YustDocSetup<T> docSetup, {
  2. List<YustFilter>? filters,
  3. int? limit,
})

Counts the number of documents in a collection.

docSetup is used to read the collection path.

filters Each entry represents a condition that has to be met. All of those conditions must be true for each returned entry.

Implementation

Future<int> count<T extends YustDoc>(YustDocSetup<T> docSetup,
    {List<YustFilter>? filters, int? limit}) async {
  final type = AggregationType.count;
  final response =
      await _retryOnException<List<RunAggregationQueryResponseElement>>(
          'count',
          _getDocumentPath(docSetup),
          () => _api.projects.databases.documents.runAggregationQuery(
              _getAggregationQuery(type, docSetup,
                  filters: filters, upTo: limit),
              _getParentPath(docSetup)));

  final result = int.parse(
      response[0].result?.aggregateFields?[type.name]?.integerValue ?? '0');
  dbLogCallback?.call(
      DatabaseLogAction.aggregate, _getDocumentPath(docSetup), result);
  return result;
}