【发布时间】:2020-11-27 11:15:37
【问题描述】:
我有过去使用 .onCreate 运行的波纹管代码,我将其更改为 .onUpdate,现在 .child() 行出现错误,表明我无法执行该操作。我该如何进行?我需要访问这些值。
export const sendNewMessageNotification = functions.database
.ref('/ChatTimelines/{uid}/{chatID}/')
.onUpdate((snapshot, context) => {
//.onCreate
const uid = context.params.uid
const otherUID = snapshot.child("otherUID").val()//error
const message = snapshot.child("lastMessage").val()//error
snapshot
//addNewLikeNotif(uid, newLikerUID, mediaNumber, timeStamp, postID)
return sendNewMessageNotificationFunc(uid, otherUID, message)
})
更新:Update2 这不起作用
(变化,上下文)
let snapshot = change.after.val()
const otherUID = snapshot.child("otherUID").val()
const message = snapshot.child("lastMessage").val()
【问题讨论】:
-
使用 onWrite 代替
-
@JayCodist 同样的结果
-
我认为
snapshot.parent.child("otherUID").val();应该可以工作。不是吗?
标签: typescript firebase firebase-realtime-database google-cloud-functions