Value Of Firebase Functions Onwrite Sometimes Is Null
Solution 1:
onWrite will trigger for any change that was matched by the location of the trigger. This means it will trigger for any create, update, or delete.
When the triggering event was a creation of new data, change.before
will be undefined (the was no data before), and change.after
will contain a snapshot.
When the triggering event is a deletion of data, change.before
will contain a snapshot, and change.after
will be undefined.
Your code is blindly assuming that change.after
contains a snapshot. It's entirely possible that deleting data is triggering your function, and it's failing because that's not what it was designed to handle.
When using onWrite, it's your obligation to check this case and handle it appropriately. If you don't care about delete events, consider using onCreate instead to just capture new data.
Post a Comment for "Value Of Firebase Functions Onwrite Sometimes Is Null"