FirestoreGoogleAppsScript icon indicating copy to clipboard operation
FirestoreGoogleAppsScript copied to clipboard

Use the count() aggregation

Open u2002020021 opened this issue 3 years ago • 0 comments

Hello :

Google add the count() aggregation query to count, please add this aggregation.

For example, count() operations that match between 0 and 1000 index entries are billed for one document read. For a count() operation that matches 1500 index entries, you are billed 2 document reads.

const coll = collection(db, "cities");
const query_ = query(coll, where('state', '==', 'CA'));
const snapshot = await getCountFromServer(query_);
console.log('count: ', snapshot.data().count);

https://firebase.google.com/docs/firestore/query-data/aggregation-queries#web-version-9_1

https://firebase.google.com/docs/firestore/pricing#aggregation_queries

u2002020021 avatar Dec 08 '22 08:12 u2002020021