【发布时间】:2018-11-17 02:40:24
【问题描述】:
我正在通过 firebase 云功能在 android 上推送通知。当我使用onWrite() 条件时,我的代码运行得非常好,我正在尝试实现此功能以进行评论,但在这种情况下,当有人编辑或喜欢评论时它会产生通知,所以我将其更改为 onCreate() 但现在我收到一个错误TypeError: Cannot read property 'val' of undefined。
在这里..
exports.pushNotificationCommentsPost = functions.database.ref('/post-comments/{postId}/{commentId}').onCreate((change, context) => {
const commentId = context.params.commentId;
const postId = context.params.postId;
const comment = change.after.val();
const posType = "Post";
const getPostTask = admin.database().ref(`/posts/${postId}`).once('value');
return getPostTask.then(post => {
// some code
})
});
我认为const comment = change.after.val(); 有问题,但我无法解决。
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions