Skip to content

added count aggregation query snippets #19

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

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/firebase_snippets_app/lib/snippets/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,33 @@ class FirestoreSnippets extends DocSnippet {
// [END perform_simple_and_compound_queries_collection_groups2]
}

void aggregationQuery_count() {
// [START count_aggregate_collection]
// Returns number of documents in users collection
db
.collection("users")
.count()
.then(
(res) => print(res.data().count),
onError: (e) => print("Error completing: $e"),
);
// [END count_aggregate_collection]
}

void aggregationQuery_count2() {
// [START count_aggregate_query]
// This also works with collectionGroup queries.
db
.collection("users")
.where("age", isGreaterThan: 10)
.count()
.then(
(res) => print(res.data().count),
onError: (e) => print("Error completing: $e"),
);
// [END count_aggregate_query]
}

void orderAndLimitData_orderAndLimitData() {
// [START order_and_limit_data_order_and_limit_data]
final citiesRef = db.collection("cities");
Expand Down