count method

Future<int> count([
  1. dynamic filter
])

Counts the number of all documents in the collection. unless according to the given filter

Implementation

Future<int> count([filter]) async {
  if (filter != null) {
    assert(filter is Map<String, dynamic> || filter is LogicalQueryOperator);

    if (filter is Map<String, dynamic>) {
      // convert 'QuerySelector' into map, too
      filter.forEach((dynamic key, value) {
        if (value is QueryOperator) {
          filter[key] = value.values;
        }
      });
    }
    if (filter is LogicalQueryOperator) {
      filter = filter.values;
    }
  }

  int size = await (FlutterMongoRealm.countDocuments(
    collectionName: this.collectionName,
    databaseName: this.databaseName,
    filter: BsonDocument(filter).toJson(),
  ));

  return size;
}