exports.createHook = functions.database.ref('/Responses/{ResponsesId}').onCreate((snap, context) => {
console.log('triggered')
var response = snap.val
console.log(response.text);
});
我已经写信给 firestore 但它没有触发,我错过了什么?
Here is a picture of my functions panel它显然部署到云端
Here is a picture of the logs它仅在构建函数时记录日志,因此它不执行。
最佳答案
I have written to firestore and it is not triggering
您可能已经写入 Firestore,但您的代码是作为 Firebase 编写的 Realtime Database trigger (它使用 functions.database
)。您需要使用 Firestore triggers响应 Firestore 中的事件(或者,您需要将更新写入实时数据库,而不是 Firestore)。
很容易混淆它们(它们的命名如此相似!),但它们并不相同,需要以不同的方式编码。
例如,Firestore onCreate
触发器的原型(prototype)应如下所示:
exports.createHook = functions.firestore
.document('Responses/{ResponsesId}')
.onCreate((change, context) => { .... }
另外,在评论线程中,我注意到您说“每次写入引用时都应调用 onCreate”。这是不正确的。 onCreate
只应在首次写入文档时调用。
关于javascript - 为什么在响应时创建文档时不触发 firebase 云功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58631959/