Cloud Functions for Firebase: How to Get the Value of Remote Data

When I add a cloud function that responds to the delete event, for example:

exports.onDeleteSector = functions.database.ref('/sectores/{idSector}').onDelete((event) =>

I can get the key to the sector to be deleted in event.params.idSector, proving that the trigger works, however it event.data.val()returns null.

The deleted entry contains links to the children that need to be deleted. How can I get them before the parent leaves?

thank

+4
source share
2 answers

event.data.val()returns null because it is the current database value at startup. For all types of database triggers, this will be the case. For onDelete, this will always be null.

, , , , event.data.previous.val(). . DeltaSnapshot, event.data.

+8

:

event.data.previous.val()
+1

Source: https://habr.com/ru/post/1681066/


All Articles