我在onDelete()firebase云功能中获得null值。以下是我的代码
exports.jobSeekerToES=functions.database.ref('/Users/{userId}/userFileDetails/files/{fileKey}').onDelete(event=>
{
var file=event.data.val();
console.log("deleted file key"+event.params.fileKey);
console.log("deleted file "+file); // file is null
});
它在日志上打印fileKey。但文件为空 请帮助我,我错了
答案 0 :(得分:14)
event.data.val()
在删除后返回位置的值。对于onDelete()
触发器,它总是为空。要在删除之前获取值,请使用事件快照的previous属性:
exports.jobSeekerToES=functions.database.ref(
'/Users/{userId}/userFileDetails/files/{fileKey}').onDelete(event=>
{
var file=event.data.previous.val(); // <= CHANGED
console.log("deleted file key"+event.params.fileKey);
console.log("deleted file "+file);
});