averageField method

num averageField(
  1. String field
)

Implementation

num averageField(String field) {
  num total = 0;
  int count = 0;
  for (final document in collection.values) {
    if (document[field] is num) {
      total += document[field];
      count++;
    }
  }
  return count > 0 ? total / count : 0;
}