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 !