Skip to content

Commit 0adab97

Browse files
committed
Add count query snippets
1 parent ea3747e commit 0adab97

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

firestore/main/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,25 @@ async function deleteQueryBatch(db, query, resolve) {
947947

948948
// [END firestore_data_delete_collection]
949949

950+
async function countAggregateCollection(db) {
951+
// [START count_aggregation_collection]
952+
const collectionRef = db.collection('cities');
953+
const snapshot = await collectionRef.count().get();
954+
955+
console.log(snapshot.data.count);
956+
// [END count_aggregation_collection]
957+
}
958+
959+
async function countAggregateQuery(db) {
960+
// [START count_aggregation_query]
961+
const collectionRef = db.collection('cities');
962+
const query = collectionRef.where('state', '==', 'CA');
963+
const snapshot = await collectionRef.count().get();
964+
965+
console.log(snapshot.data.count);
966+
// [END count_aggregation_query]
967+
}
968+
950969
// ============================================================================
951970
// MAIN
952971
// ============================================================================

0 commit comments

Comments
 (0)