getCount method
Retrieves the count of documents in the collection based on the specified filters.
You can filter documents by providing a field
and value
, or by specifying a
more complex filter
using a map. If no filter is provided, the total count of
documents in the collection is returned.
Returns the count of matching documents.
Implementation
Future<int> getCount({
String? field,
Object? value,
Map<String, Object?>? filter,
}) async {
if (field != null && value != null) {
var count = await collection.modernCount(
selector: where.eq(field, value), filter: filter);
return count.count;
}
return (await collection.modernCount(filter: filter)).count;
}