Cloud Functions for Firebase: How to get the value of the data that was deleted

Viewed 1763

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

3 Answers

Current way of getting the deleted data from onDelete trigger is like this:

exports.userDeleted = functions.firestore
  .document("users/{userId}")
  .onDelete((snapshot) => {
    const original = snapshot.data();
    // original contains the deleted data
  });
Related