且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firebase TypeError:无法读取未定义的属性“val”

更新时间:2023-11-05 15:50:10

更改此内容:

exports.pushNotification = functions.database.ref('/messages').onWrite( event => {

const message = event.data.val();
const user = event.data.val();
});

到此:

exports.pushNotification = functions.database.ref('/messages').onWrite(( change,context) => {

const message = change.after.val();
});

请检查:

https://firebase.google.com/docs/functions/beta-v1 -diff#realtime-database

云功能已更改,现在 onWrite 有两个参数更改上下文

The cloud functions were changed and now onWrite has two parameters change and context

更改在之前有两个属性,在之后有,并且每个属性都是 DataSnapshot 使用此处列出的方法:

The change has two properties before and after and each of these is a DataSnapshot with the methods listed here:

https://firebase.google.com/docs/reference/admin/node/admin.database.DataSnapshot