0

When using Firestore database and Firestore functions, I am trying to achieve a way to keep documents count of a specific collection limited (For example, I don't want the collection to have more than MAX_COUNT documents).

This is the template of what I want to achieve (a Javascript script in index.js):

exports.docAdded = functions.firestore.document('myCollection/{docID}').onWrite((change, context) => {
 if (!change.before.exists) {
     // New document Created - check total number of documents in myCollection
       //- Delete old documents in case of size>MAX_COUNT
 }
});

Any help is appreciated !

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Daher928
  • 35
  • 6

1 Answers1

1

There isn't a function developed yet, that supports the tracking of the number of documents in a collection. However, there are some alternatives and methods that you can give it a try, to help you achieve this limitation goal that you want.

I would recommend you to take a look at the below articles and posts from the Community, that might help you and provide some ideas on how to achieve this.

Let me know if the information helped you!

gso_gabriel
  • 4,199
  • 1
  • 10
  • 22