-
Notifications
You must be signed in to change notification settings - Fork 15
feat(firestore): add samples for sum and average #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Lyokone ! Two comments:
- The current examples in the docs use the
cities
example, can we use that same collection for consistency? (I have added suggested edits below) - Can you please also add a snippet for multiple aggregations in a query?
db.collection("users").aggregate(sum("age")).get().then( | ||
(res) => print(res.getAverage("age")), | ||
onError: (e) => print("Error completing: $e"), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db.collection("users").aggregate(sum("age")).get().then( | |
(res) => print(res.getAverage("age")), | |
onError: (e) => print("Error completing: $e"), | |
); | |
db.collection("cities").aggregate(sum("population")).get().then( | |
(res) => print(res.getAverage("population")), | |
onError: (e) => print("Error completing: $e"), | |
); |
.collection("users") | ||
.where("age", isGreaterThan: 10) | ||
.aggregate(sum("age")) | ||
.get() | ||
.then( | ||
(res) => print(res.getAverage("age")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collection("users") | |
.where("age", isGreaterThan: 10) | |
.aggregate(sum("age")) | |
.get() | |
.then( | |
(res) => print(res.getAverage("age")), | |
.collection("cities") | |
.where("capital", isEqualTo: true) | |
.aggregate(sum("population")) | |
.get() | |
.then( | |
(res) => print(res.getAverage("population")), |
db.collection("users").aggregate(average("age")).get().then( | ||
(res) => print(res.getAverage("age")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
db.collection("users").aggregate(average("age")).get().then( | |
(res) => print(res.getAverage("age")), | |
db.collection("cities").aggregate(average("population")).get().then( | |
(res) => print(res.getAverage("population")), |
.collection("users") | ||
.where("age", isGreaterThan: 10) | ||
.aggregate(average("age")) | ||
.get() | ||
.then( | ||
(res) => print(res.getAverage("age")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.collection("users") | |
.where("age", isGreaterThan: 10) | |
.aggregate(average("age")) | |
.get() | |
.then( | |
(res) => print(res.getAverage("age")), | |
.collection("cities") | |
.where("capital", isEqualTo: true) | |
.aggregate(average("population")) | |
.get() | |
.then( | |
(res) => print(res.getAverage("population")), |
Thanks @thatfiredev for the review. In this case, should we also update the count snippets to use cities example? |
@cynthiajoan Oh, I hadn't noticed that one was using a different example. Yes, let's use cities there too please. :) |
Hmmm, not sure why CI is failing (both here and in #36), but some posts suggest upgrading packages. Can we try that @Lyokone ? Error log for reference:
|
#38 to try fixing the CI |
…nto sumaverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing CI @cynthiajoan !
I'll update https://firebase.google.com/docs/firestore/query-data/aggregation-queries accordingly.
Description of what this PR is changing or adding:
_Issues fixed by this PR (if any): firebase/flutterfire#13062
Risk Level
Pre-submit checklist