@@ -842,32 +842,33 @@ class FirestoreSnippets extends DocSnippet {
842
842
843
843
void filterQuery_or () {
844
844
// [START firestore_query_filter_or]
845
- var query = db.collection ("cities" )
846
- . where (
847
- Filter . or (
848
- Filter ("capital " , isEqualTo : true ),
849
- Filter ( "population" , isGreaterThan : 1000000 )
850
- )) ;
845
+ var query = db.collection ("cities" ). where (
846
+ Filter . or (
847
+ Filter ( "capital" , isEqualTo : true ),
848
+ Filter ("population " , isGreaterThan : 1000000 ),
849
+ ),
850
+ );
851
851
// [END firestore_query_filter_or]
852
852
}
853
853
854
854
void filterQuery_or2 () {
855
855
// [START firestore_query_filter_or_compound]
856
- var query = db.collection ("cities" )
857
- .where (
858
- Filter .and (
859
- Filter ("state" , isEqualTo: "CA" ),
860
- Filter .or (
861
- Filter ("capital" , isEqualTo: true ),
862
- Filter ("population" , isGreaterThan: 1000000 )
863
- )));
856
+ var query = db.collection ("cities" ).where (
857
+ Filter .and (
858
+ Filter ("state" , isEqualTo: "CA" ),
859
+ Filter .or (
860
+ Filter ("capital" , isEqualTo: true ),
861
+ Filter ("population" , isGreaterThan: 1000000 ),
862
+ ),
863
+ ),
864
+ );
864
865
// [END firestore_query_filter_or_compound]
865
866
}
866
867
867
868
void aggregationQuery_count () {
868
869
// [START count_aggregate_collection]
869
870
// Returns number of documents in users collection
870
- db.collection ("users " ).count ().get ().then (
871
+ db.collection ("cities " ).count ().get ().then (
871
872
(res) => print (res.count),
872
873
onError: (e) => print ("Error completing: $e " ),
873
874
);
@@ -876,14 +877,81 @@ class FirestoreSnippets extends DocSnippet {
876
877
877
878
void aggregationQuery_count2 () {
878
879
// [START count_aggregate_query]
879
- // This also works with collectionGroup queries.
880
- db.collection ("users " ).where ("age " , isGreaterThan : 10 ).count ().get ().then (
880
+ // This also works with collection queries.
881
+ db.collection ("cities " ).where ("capital " , isEqualTo : 10 ).count ().get ().then (
881
882
(res) => print (res.count),
882
883
onError: (e) => print ("Error completing: $e " ),
883
884
);
884
885
// [END count_aggregate_query]
885
886
}
886
887
888
+ void aggregationQuery_sum () {
889
+ // [START sum_aggregate_collection]
890
+ db.collection ("cities" ).aggregate (sum ("population" )).get ().then (
891
+ (res) => print (res.getAverage ("population" )),
892
+ onError: (e) => print ("Error completing: $e " ),
893
+ );
894
+ // [END sum_aggregate_collection]
895
+ }
896
+
897
+ void aggregationQuery_sum2 () {
898
+ // [START sum_aggregate_query]
899
+ db
900
+ .collection ("cities" )
901
+ .where ("capital" , isEqualTo: true )
902
+ .aggregate (sum ("population" ))
903
+ .get ()
904
+ .then (
905
+ (res) => print (res.getAverage ("population" )),
906
+ onError: (e) => print ("Error completing: $e " ),
907
+ );
908
+ // [END sum_aggregate_query]
909
+ }
910
+
911
+ void aggregationQuery_average () {
912
+ // [START average_aggregate_collection]
913
+ db.collection ("cities" ).aggregate (average ("population" )).get ().then (
914
+ (res) => print (res.getAverage ("population" )),
915
+ onError: (e) => print ("Error completing: $e " ),
916
+ );
917
+ // [END average_aggregate_collection]
918
+ }
919
+
920
+ void aggregationQuery_average2 () {
921
+ // [START average_aggregate_query]
922
+ db
923
+ .collection ("cities" )
924
+ .where ("capital" , isEqualTo: true )
925
+ .aggregate (average ("population" ))
926
+ .get ()
927
+ .then (
928
+ (res) => print (res.getAverage ("population" )),
929
+ onError: (e) => print ("Error completing: $e " ),
930
+ );
931
+ // [END average_aggregate_query]
932
+ }
933
+
934
+ void multipleAggregateQueries () {
935
+ // [START multiple_aggregate_queries]
936
+ db
937
+ .collection ("cities" )
938
+ .aggregate (
939
+ count (),
940
+ sum ("population" ),
941
+ average ("population" ),
942
+ )
943
+ .get ()
944
+ .then (
945
+ (res) {
946
+ print (res.count);
947
+ print (res.getSum ("population" ));
948
+ print (res.getAverage ("population" ));
949
+ },
950
+ onError: (e) => print ("Error completing: $e " ),
951
+ );
952
+ // [END multiple_aggregate_queries]
953
+ }
954
+
887
955
void orderAndLimitData_orderAndLimitData () {
888
956
// [START order_and_limit_data_order_and_limit_data]
889
957
final citiesRef = db.collection ("cities" );
@@ -970,7 +1038,8 @@ class FirestoreSnippets extends DocSnippet {
970
1038
final next = db
971
1039
.collection ("cities" )
972
1040
.orderBy ("population" )
973
- .startAfterDocument (lastVisible).limit (25 );
1041
+ .startAfterDocument (lastVisible)
1042
+ .limit (25 );
974
1043
975
1044
// Use the query for pagination
976
1045
// ...
0 commit comments