【问题标题】:firestore changes not triggeringfirestore 更改未触发
【发布时间】:2019-02-13 20:32:45
【问题描述】:

我觉得我至少应该看到一个错误,或者..如果一反常态地幸运,成功。我在/sampleData/metrics/{uid}/{document} 上有一个活动设置,你可以在这里看到:

请注意,触发器包含前导/。在我的第一次部署中,它也没有在代码中指定它。当我第一次测试时没有看到调用时,我改变了它,但是那里的 console.firebase.google.com 中的文本没有改变......但是,随后的部署看起来确实完成了:

=== Deploying to 'THIS PROJECT'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing . directory for uploading...
i  functions: packaged . (172.19 KB) for uploading
✔  functions: . folder uploaded successfully
i  functions: updating Node.js 8 function onAddLocation(us-central1)...
i  functions: updating Node.js 8 function onAddMetric(us-central1)...
✔  functions[onAddLocation(us-central1)]: Successful update operation. 
✔  functions[onAddMetric(us-central1)]: Successful update operation. 

✔  Deploy complete!

Please note that it can take up to 30 seconds for your updated functions to propagate.
Project Console: https://console.firebase.google.com/project/THIS PROJECT/overview
✨  Done in 51.23s.

我们还可以看到我的示例应用正在那里添加数据:

但是当我添加数据时,我没有看到我的函数被触发。功能 -> 使用选项卡上的计数仍为 0,甚至在几分钟后:

我的函数在节点 8 中并使用 async/await,但是 package.json 和 firebase.json 都指定了

"engines": {
  "node": "8"
},

注意事项:

添加了用法选项卡的屏幕截图,显示console.log 可能不会说什么。

【问题讨论】:

  • 您可以在函数中使用console.log(),然后单击函数仪表板中的“日志”选项卡以验证它们是否被触发。事件发生后通常需要大约 30 秒才能看到 Web 仪表板中显示的日志。
  • @miles_b console.log 调用可能需要在它们发生之前调用该函数.. 我在某种程度上错了吗??

标签: firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

由于您的 Functions 仪表板显示触发器“ref.write”,这意味着当您写入 实时数据库 而不是 Cloud Firestore 时会触发您的 Cloud Function。它们是 Firebase 提供的两种不同的数据库服务。

您必须按照此文档调整您的代码:https://firebase.google.com/docs/functions/firestore-events?authuser=0

例如:

exports.firestoreTrigger = functions.firestore
  .document('/sampleData/metrics/{uid}/{document}')
  .onCreate((snapshot, context) => {
    const msgData = snapshot.data();
    console.log(msgData);
    return null;
  });

【讨论】:

  • 谢谢。只是给那些犯了同样错误的人做个注释,在更改触发器后重新部署时,我得到了⚠ functions: failed to update function onAddLocation HTTP Error: 400, Change of function trigger type or event provider is not allowed——所以我必须先从控制台中删除这些函数。
猜你喜欢
  • 2020-01-02
  • 1970-01-01
  • 2020-01-20
  • 1970-01-01
  • 2021-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多