首页 > 解决方案 > Firebase 函数对 firestore 创建事件做出反应

问题描述

export const onCommentCreated = functions.firestore.document('Comment/{gameName}/{post}').onCreate((snapshot, context) => {
    const docRef = admin.firestore().collection('Gamefeed').doc(context.params.gameName).collection('Posts').doc(context.params.post)
    docRef.update({
            amountOfComments: 99
        }).then(response => {
            return
        }).catch(error => {
            return
        })
})

这是我试图部署到 Firebase 的功能。不知何故,这不起作用。因为我得到

functions: failed to create function onCommentCreated
HTTP Error: 400, The request has errors

我不知道为什么它不起作用。创建此函数时,我遵循https://firebase.google.com/docs/functions/firestore-events作为参考点。

我可以补充一点,我试图删除函数的内容,只是添加了一个 return 语句。部署仍然不起作用。所以我的猜测是这条线有问题

export const onCommentCreated = functions.firestore.document('Comment/{gameName}/{post}').onCreate((snapshot, context) => {

标签: firebasegoogle-cloud-firestoregoogle-cloud-functions

解决方案


您正在收听收藏。

你应该听文档创建,所以它应该是

exports.onCommentCreated = functions.firestore.document('Comment/{gameName}/{post}/{postId}').onCreate((snapshot, context) => {

推荐阅读