Skip to content

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

@CaduRomaniello

Description

@CaduRomaniello

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:

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions