【发布时间】:2020-10-15 18:21:51
【问题描述】:
我正在尝试部署一个简单的 Firestore Cloud 功能,但无法部署。编译器也没有告诉我错误是什么。有人可以帮我吗。有人说第二个参数不应该是通配符,但这样的事情是零意义的。
exports.checkIfScannerExists = functions.firestore.document('Scanner_Number_Check/{push_id}/Phone').onWrite((change, context) => {
if(change.after.exists())
{
const push_id = context.params.push_id;
const phone_number = change.after.val();
admin.firestore().collection('Store_Logins').where('Phone', '==', phone_number).get()
.then(snapshot => {
if(snapshot.empty)
{
admin.firestore().collection('Scanner_Number_Check').collection(push_id).collection('Response').set("No")
return;
}
else
{
admin.firestore().collection('Scanner_Number_Check').collection(push_id).collection('Response').set("No")
return;
}
})
}
return null;
})
【问题讨论】:
-
您遇到了哪个错误?编译器显示什么?此外,请注意您没有正确返回承诺链。
-
另外,如果您执行相同的操作,无论
if检查的结果是什么,为什么还要使用if? -
抱歉,我搞砸了 if 语句,因为它只是一个基本示例。是的,我的承诺没有得到适当的回报。谢谢!
-
另外,如果路径中的节点数是奇数,您似乎无法实现 onWrite 函数。参考:stackoverflow.com/questions/46639058/…
-
是的!我没有抓住这个...正如doc 中所说的“您的触发器必须始终指向一个文档,即使您使用的是通配符。”答案改编!
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions