我已经编写了下面的代码,以检测何时将注释添加到数据库,然后通过更新时间轴节点进行响应,问题是它实际上并未更新。 为什么不起作用?
export const onCommentAdded = functions.database
.ref('/Comments/{receiverUID}/{postID}/{mediaNum}/{commentID}')
.onCreate((snapshot, context) => {
const uid = context.params.uid
const newCommentUID = snapshot.child("UID").val()
console.log(newCommentUID, " the comment")
return addNewCommentNotif(uid, newCommentUID)
})
function addNewCommentNotif(uuid: string, newCommentUID: string) {
//NotifTimeline/uid/NewNotif (someuniqueVal)/commentID
const randID = Math.floor(100000000 + Math.random() * 900000000);
const notifTimelineRef = admin.database().ref("NotifTimeline").child(uuid).child(newCommentUID + ":" + randID).child("NewComment")
notifTimelineRef.set(newCommentUID)//update
.then(() => {
console.log("Success updating this uid comment timeline")
})
.catch((error: string) => {
console.log("Error in catch: "+error)
response.status(500).send(error)
})
return Promise.resolve();
}
答案 0 :(得分:1)
返回set()返回的承诺:
function addNewCommentNotif(uuid: string, newCommentUID: string) {
//NotifTimeline/uid/NewNotif (someuniqueVal)/commentID
const randID = Math.floor(100000000 + Math.random() * 900000000);
const notifTimelineRef = admin.database().ref("NotifTimeline").child(uuid).child(newCommentUID + ":" + randID).child("NewComment")
return notifTimelineRef.set(newCommentUID)//update
.then(() => {
console.log("Success updating this uid comment timeline")
})
.catch((error: string) => {
console.log("Error in catch: "+error)
response.status(500).send(error)
})
}
答案 1 :(得分:1)
ToraCode在他说的话中正确地说:
我认为是因为您的const uid = context.params.uid。我在您的引用中看不到任何参数名称uid