grahamearley / FirestoreGoogleAppsScript

A Google Apps Script library for accessing Google Cloud Firestore.
http://grahamearley.website/blog/2017/10/18/firestore-in-google-apps-script.html
MIT License
648 stars 109 forks source link

Use the count() aggregation #151

Open u2002020021 opened 1 year ago

u2002020021 commented 1 year ago

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