File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
packages/firebase_snippets_app/lib/snippets Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -804,6 +804,33 @@ class FirestoreSnippets extends DocSnippet {
804804 // [END perform_simple_and_compound_queries_collection_groups2]
805805 }
806806
807+ void aggregationQuery_count () {
808+ // [START count_aggregate_collection]
809+ // Returns number of documents in users collection
810+ db
811+ .collection ("users" )
812+ .count ()
813+ .then (
814+ (res) => print (res.data ().count),
815+ onError: (e) => print ("Error completing: $e " ),
816+ );
817+ // [END count_aggregate_collection]
818+ }
819+
820+ void aggregationQuery_count2 () {
821+ // [START count_aggregate_query]
822+ // This also works with collectionGroup queries.
823+ db
824+ .collection ("users" )
825+ .where ("age" , isGreaterThan: 10 )
826+ .count ()
827+ .then (
828+ (res) => print (res.data ().count),
829+ onError: (e) => print ("Error completing: $e " ),
830+ );
831+ // [END count_aggregate_query]
832+ }
833+
807834 void orderAndLimitData_orderAndLimitData () {
808835 // [START order_and_limit_data_order_and_limit_data]
809836 final citiesRef = db.collection ("cities" );
You can’t perform that action at this time.
0 commit comments