Home > Software design >  How to use count() method in Firestore transaction?
How to use count() method in Firestore transaction?

Time:11-07

I have a callable cloud function (node.js) which runs a transaction with numerous writes and reads. One of those reads should be a count() read:

const count = await transaction.get(db.collection("posts").count());

However, this doesn't seem to work as I get an error. Perhaps this method isn't yet a part of transactions?

CodePudding user response:

The support for count() queries was added in [email protected] and transaction.get() takes either a DocumentReference or a Query (also AggregateQuery) so that should work. Try updating to latest version of firebase-admin.

npm i firebase-admin@latest
  • Related