Skip to content
Merged
Show file tree
Hide file tree
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 firestore/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,25 @@ async function deleteQueryBatch(db, query, resolve) {

// [END firestore_data_delete_collection]

async function countAggregateCollection(db) {
// [START count_aggregation_collection]
const collectionRef = db.collection('cities');
const snapshot = await collectionRef.count().get();

console.log(snapshot.data.count);
// [END count_aggregation_collection]
}

async function countAggregateQuery(db) {
// [START count_aggregation_query]
const collectionRef = db.collection('cities');
const query = collectionRef.where('state', '==', 'CA');
const snapshot = await collectionRef.count().get();

console.log(snapshot.data.count);
// [END count_aggregation_query]
}

// ============================================================================
// MAIN
// ============================================================================
Expand Down Expand Up @@ -1165,4 +1184,12 @@ describe('Firestore Smoketests', () => {
it('should find all museums when querying a collection group', () => {
return collectionGroupQuery(db);
});

it('should count the number of documents in a collection', () => {
return countAggregateCollection(db);
});

it('should count the number of documents in a filtered query', () => {
return countAggregateQuery(db);
});
});
Loading
Loading