0
votes

I am trying to limit document creation of my each subscriber for a certain number of documents.

In my cloud function, I create an onCreate trigger and even I return "null" if document count doesn't match with my limits, firestore still creates this document.

I digged into firestore and cloud functions documentations but could not find any example how to cancel/abort a cloud function trigger.

Bonus question; Do I have any way to alert customer wheter he/she exceeded the limit of this document creation? I thought I can update a seperate alert document in my trigger function and read and display this to customer. Do you know any way to listen onCreate trigger's result and display the error real time?

Any help please? Many Thanks.

1

1 Answers

3
votes

What you're trying to do isn't possible. Cloud Functions respond to events that occur within some product (such as Firestore). The event indicates that some change already happened. All you can do is choose what you want to do in response to that event. You can't prevent the change from taking place. The best you could do is undo the change by performing the opposite of what already happened. So, if a document was created, and that violates whatever rules you want to enforce, then you can simply delete the document.