@@ -982,6 +982,25 @@ async function deleteQueryBatch(db, query, resolve) {
982982
983983// [END firestore_data_delete_collection]
984984
985+ async function countAggregateCollection ( db ) {
986+ // [START count_aggregation_collection]
987+ const collectionRef = db . collection ( 'cities' ) ;
988+ const snapshot = await collectionRef . count ( ) . get ( ) ;
989+
990+ console . log ( snapshot . data . count ) ;
991+ // [END count_aggregation_collection]
992+ }
993+
994+ async function countAggregateQuery ( db ) {
995+ // [START count_aggregation_query]
996+ const collectionRef = db . collection ( 'cities' ) ;
997+ const query = collectionRef . where ( 'state' , '==' , 'CA' ) ;
998+ const snapshot = await collectionRef . count ( ) . get ( ) ;
999+
1000+ console . log ( snapshot . data . count ) ;
1001+ // [END count_aggregation_query]
1002+ }
1003+
9851004// ============================================================================
9861005// MAIN
9871006// ============================================================================
@@ -1165,4 +1184,12 @@ describe('Firestore Smoketests', () => {
11651184 it ( 'should find all museums when querying a collection group' , ( ) => {
11661185 return collectionGroupQuery ( db ) ;
11671186 } ) ;
1187+
1188+ it ( 'should count the number of documents in a collection' , ( ) => {
1189+ return countAggregateCollection ( db ) ;
1190+ } ) ;
1191+
1192+ it ( 'should count the number of documents in a filtered query' , ( ) => {
1193+ return countAggregateQuery ( db ) ;
1194+ } ) ;
11681195} ) ;
0 commit comments