@@ -823,32 +823,25 @@ class FirestoreSnippets extends DocSnippet {
823
823
824
824
void filterQuery_or () {
825
825
// [START firestore_query_filter_or]
826
- var query = db.collection ("cities" )
827
- .where (
828
- Filter .or (
829
- Filter ("capital" , isEqualTo: true ),
830
- Filter ("population" , isGreaterThan: 1000000 )
831
- ));
826
+ var query = db.collection ("cities" ).where (Filter .or (
827
+ Filter ("capital" , isEqualTo: true ),
828
+ Filter ("population" , isGreaterThan: 1000000 )));
832
829
// [END firestore_query_filter_or]
833
830
}
834
831
835
832
void filterQuery_or2 () {
836
833
// [START firestore_query_filter_or_compound]
837
- var query = db.collection ("cities" )
838
- .where (
839
- Filter .and (
840
- Filter ("state" , isEqualTo: "CA" ),
841
- Filter .or (
842
- Filter ("capital" , isEqualTo: true ),
843
- Filter ("population" , isGreaterThan: 1000000 )
844
- )));
834
+ var query = db.collection ("cities" ).where (Filter .and (
835
+ Filter ("state" , isEqualTo: "CA" ),
836
+ Filter .or (Filter ("capital" , isEqualTo: true ),
837
+ Filter ("population" , isGreaterThan: 1000000 ))));
845
838
// [END firestore_query_filter_or_compound]
846
839
}
847
840
848
841
void aggregationQuery_count () {
849
842
// [START count_aggregate_collection]
850
843
// Returns number of documents in users collection
851
- db.collection ("users " ).count ().get ().then (
844
+ db.collection ("cities " ).count ().get ().then (
852
845
(res) => print (res.count),
853
846
onError: (e) => print ("Error completing: $e " ),
854
847
);
@@ -857,8 +850,8 @@ class FirestoreSnippets extends DocSnippet {
857
850
858
851
void aggregationQuery_count2 () {
859
852
// [START count_aggregate_query]
860
- // This also works with collectionGroup queries.
861
- db.collection ("users " ).where ("age " , isGreaterThan : 10 ).count ().get ().then (
853
+ // This also works with collection queries.
854
+ db.collection ("cities " ).where ("capital " , isEqualTo : 10 ).count ().get ().then (
862
855
(res) => print (res.count),
863
856
onError: (e) => print ("Error completing: $e " ),
864
857
);
@@ -867,8 +860,8 @@ class FirestoreSnippets extends DocSnippet {
867
860
868
861
void aggregationQuery_sum () {
869
862
// [START sum_aggregate_collection]
870
- db.collection ("users " ).aggregate (sum ("age " )).get ().then (
871
- (res) => print (res.getAverage ("age " )),
863
+ db.collection ("cities " ).aggregate (sum ("population " )).get ().then (
864
+ (res) => print (res.getAverage ("population " )),
872
865
onError: (e) => print ("Error completing: $e " ),
873
866
);
874
867
// [END sum_aggregate_collection]
@@ -877,21 +870,21 @@ class FirestoreSnippets extends DocSnippet {
877
870
void aggregationQuery_sum2 () {
878
871
// [START sum_aggregate_query]
879
872
db
880
- .collection ("users " )
881
- .where ("age " , isGreaterThan : 10 )
882
- .aggregate (sum ("age " ))
873
+ .collection ("cities " )
874
+ .where ("capital " , isEqualTo : true )
875
+ .aggregate (sum ("population " ))
883
876
.get ()
884
877
.then (
885
- (res) => print (res.getAverage ("age " )),
878
+ (res) => print (res.getAverage ("population " )),
886
879
onError: (e) => print ("Error completing: $e " ),
887
880
);
888
881
// [END sum_aggregate_query]
889
882
}
890
883
891
884
void aggregationQuery_average () {
892
885
// [START average_aggregate_collection]
893
- db.collection ("users " ).aggregate (average ("age " )).get ().then (
894
- (res) => print (res.getAverage ("age " )),
886
+ db.collection ("cities " ).aggregate (average ("population " )).get ().then (
887
+ (res) => print (res.getAverage ("population " )),
895
888
onError: (e) => print ("Error completing: $e " ),
896
889
);
897
890
// [END average_aggregate_collection]
@@ -900,17 +893,38 @@ class FirestoreSnippets extends DocSnippet {
900
893
void aggregationQuery_average2 () {
901
894
// [START average_aggregate_query]
902
895
db
903
- .collection ("users " )
904
- .where ("age " , isGreaterThan : 10 )
905
- .aggregate (average ("age " ))
896
+ .collection ("cities " )
897
+ .where ("capital " , isEqualTo : true )
898
+ .aggregate (average ("population " ))
906
899
.get ()
907
900
.then (
908
- (res) => print (res.getAverage ("age " )),
901
+ (res) => print (res.getAverage ("population " )),
909
902
onError: (e) => print ("Error completing: $e " ),
910
903
);
911
904
// [END average_aggregate_query]
912
905
}
913
906
907
+ void multipleAggregateQueries () {
908
+ // [START multiple_aggregate_queries]
909
+ db
910
+ .collection ("cities" )
911
+ .aggregate (
912
+ count (),
913
+ sum ("population" ),
914
+ average ("population" ),
915
+ )
916
+ .get ()
917
+ .then (
918
+ (res) {
919
+ print (res.count);
920
+ print (res.getSum ("population" ));
921
+ print (res.getAverage ("population" ));
922
+ },
923
+ onError: (e) => print ("Error completing: $e " ),
924
+ );
925
+ // [END multiple_aggregate_queries]
926
+ }
927
+
914
928
void orderAndLimitData_orderAndLimitData () {
915
929
// [START order_and_limit_data_order_and_limit_data]
916
930
final citiesRef = db.collection ("cities" );
@@ -997,7 +1011,8 @@ class FirestoreSnippets extends DocSnippet {
997
1011
final next = db
998
1012
.collection ("cities" )
999
1013
.orderBy ("population" )
1000
- .startAfterDocument (lastVisible).limit (25 );
1014
+ .startAfterDocument (lastVisible)
1015
+ .limit (25 );
1001
1016
1002
1017
// Use the query for pagination
1003
1018
// ...
0 commit comments