【发布时间】:2020-07-31 07:44:00
【问题描述】:
我的 firestore 中有 2 个集合(全局和本地),当我将文档添加到本地时,我需要将全局文档中的字段更新 1
下面是我的代码。我对此很陌生,所以我也可能有一些语法错误,如果你发现任何问题,请高亮显示。
const functions = require("firebase-functions");
const admin = require("firebase-admin");
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello world");
}); // For testing, even this is not being deployed
exports.updateGlobal = functions.firestore
.document("/local/{id}")
.onCreate((snapshot, context) => {
console.log(snapshot.data());
return admin
.firebase()
.doc("global/{id}")
.update({
total: admin.firestore.FieldValue.increment(1),
});
});
终端显示“加载用户代码时功能失败” 在此之前,它显示了“管理员未定义”或“无法访问未定义的 firestore”之类的内容,我现在无法复制。
这是通过 firebase npm 模块正常运行的 react 应用程序的一部分 有关该问题所需的任何其他信息,我将相应地编辑问题,非常感谢您的帮助。
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore google-cloud-functions