gpt4 book ai didi

google-cloud-firestore - 升级到 Cloud Functions v1.0,我打破了一切

转载 作者:行者123 更新时间:2023-12-03 23:16:36 24 4
gpt4 key购买 nike

尝试按照 this page 上的说明进行操作我不知道如何简单地获取 DocumentSnapshot 中的数据。

他们并没有真正解释更新 onCreate,只是说它与 onDelete 相同,我无法让它发挥作用。

 exports.mFoo = functions.firestore
.document('foos/{key}')
.onCreate((snap, context) => {

const bar = snap.data(); // <-- DOESN'T WORK
console.log(bar); // <-- DOESN'T WORK

return Promise;
});

我收到以下错误:

TypeError: snap.data is not a function at exports.mFoo.functions.firestore.document.onCreate



我确定它非常简单,但我不太了解这些东西,我尝试了大量的东西组合,但没有任何效果。

最佳答案

结果我遇到了和我一样的问题 before .

在执行任何这些类型的更新之前:

npm install firebase-functions@latest --save
npm install firebase-admin@5.11.0 --save
npm install -g firebase-tools

首先,我必须打开我的 package.json 文件并删除将要更新的所有依赖项。

这些是我在那里找到的:
 "dependencies": {
"firebase-admin": "~5.8.1",
"firebase-functions": "^0.8.1"
},

在将依赖项留空并重新运行这些命令进行安装后,这些出现了:
 "dependencies": {
"firebase-admin": "^5.11.0",
"firebase-functions": "^1.0.1"
},

显然,安装和升级不会修复这些依赖项,但如果它们不存在,他们会添加它们。也许可以通过输入它们来修复它,但我不知道要在那里放置什么版本号。

现在(修改后的)代码有效:
 exports.mFoo = functions.firestore
.document('foos/{key}')
.onCreate((snap, context) => {

const bar = snap.data(); // now this works
console.log(bar.baz); // <-- before I wasn't referring to anything in the snapshot

return Promise; // I. Promised. Nothing.
});

感谢 @Todd Kerpelman为我指明了正确的方向和 @Bob Snyder因为来自 other post 的相同答案也在这里为我工作。

关于google-cloud-firestore - 升级到 Cloud Functions v1.0,我打破了一切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49822579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com