3
votes

Recently I created a firebase functions code which triggers when certain document is deleted in Firestore. It works perfectly fine when I am deleting the document programmatically, but it does not work when I am deleting the document from Firebase Console.

Actually I also have sub-collection inside the document which I need even if the document data is deleted. So from firebase console I cannot 'Delete document' but I need to 'Delete document fields' which will prevent deleting my sub-collections.

Also when I delete a document with sub-collection programmatically, it deletes only the document fields and not the entire document with sub-collections. So why is onDelete triggered when deleting document programmatically but not when deleting document fields from firebase console. The 1st picture is the document which was deleted programmatically and 2nd one is the one I deleted from firebase console.

What should I do to trigger onDelete firebase function when deleting document manually from Firebase Console without deleting sub-collections ?

This is the document that was deleted programmatically

This is the document that was deleted manually from firebase console

1

1 Answers

1
votes

Although this is not mentioned in the Firestore documentation, Event Triggers for Firestore are not triggered by changes made manually in the console.

The reasons for it is that at the end of the day, manual changes should be avoided to preserve data integrity, specially if you are at a stage of your app's development that already has event triggers to make database sanitation.

If you'd like to have this explicitly stated in the Firestore documentation, you could open a request in Google's issue tracker so that it can be done, or you could open a Feature Request so that this functionality of triggers for Firestore is considered for next releases of Firestore.