firebase - 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) => {
解决方案
您正在收听收藏。
你应该听文档创建,所以它应该是
exports.onCommentCreated = functions.firestore.document('Comment/{gameName}/{post}/{postId}').onCreate((snapshot, context) => {
推荐阅读
- python - 为什么添加散点图时此图会失败,但删除它时它会起作用?
- bigdata - Dataproc 的基本概念:它是如何运作的?
- c# - 以字节的形式显示Hex值
- node.js - 访问 Sequelize 模型上的单个字段
- virtual-machine - 在 fedora14 上安装 VMWare 工具失败并显示“initctl: Job failed to start”
- excel - 如何将行传递给 Excel(Visual Basic for Applications)自定义函数?
- ios - 配置 AdMob 后随机弹出麦克风权限
- python - 如何在 Python 中制作动画?
- android - Android kotlin - 检查 null 或 empty 是否返回无意义
- label - 如何自定义等高线标签?