snippets-flutter icon indicating copy to clipboard operation
snippets-flutter copied to clipboard

docs(cloud_firestore): Aggregation queries sum example uses incorrect method

Open CaduRomaniello opened this issue 5 months ago • 0 comments

Description for the Issue

Hi, Firebase team!

I've identified a small documentation bug that could be confusing to other developers. In the "Use the sum() aggregation" section of the aggregation queries documentation, the example code for the sum aggregation is calling the getAverage() method instead of getSum().

Reference:

  • Page: https://firebase.google.com/docs/firestore/query-data/aggregation-queries
  • Section: "Use the sum() aggregation"

Incorrect code

db.collection("cities").aggregate(sum("population")).get().then(
  (res) => print(res.getAverage("population")),
  onError: (e) => print("Error completing: $e"),
);

Correct code For the example to work as expected, the method call should be res.getSum("population").

Suggested Correct Code:

db.collection("cities").aggregate(sum("population")).get().then(
  (res) => print(res.getSum("population")),
  onError: (e) => print("Error completing: $e"),
);

It also occurs in the second example of this section where it shows that sum()aggregation considers all filters in the query and any limit clauses. It's worth to mention that i only saw this inconsistency in the dart/flutter example.

Thanks!

CaduRomaniello avatar Sep 15 '25 18:09 CaduRomaniello