When I add a cloud function responding to a delete event, like this one:
exports.onDeleteSector = functions.database.ref('/sectores/{idSector}').onDelete((event) =>
I can get the key to the sector being deleted in event.params.idSector
proving the trigger works, however, event.data.val()
returns null.
The deleted record contains the references to the children to be deleted. How can I get those before the parent is gone?
Thanks
event.data.val()
returns null, because that's the current value of the database at the time of the trigger. For all kinds of database triggers, this is going to be the case. For onDelete, this will always be null.
If you want to see what was previously at that location, before the event happened, take a look at event.data.previous.val()
. Also see the docs for DeltaSnapshot, which is the data type for event.data
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With