firestore更改不会触发

问题描述 投票:0回答:1

我觉得我至少应该看到一个错误,或者......如果一反常态,那就是成功。我在/sampleData/metrics/{uid}/{document}上设置了一个事件,你可以在这里看到:

dashboard - functions

请注意,触发器不包含前导/。在我的第一次部署时,它没有在代码中指定它。我在第一次测试时没有看到调用时更改了,但是在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.

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

dashboard - database

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

dashboard - functions - usage

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

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

notes:

添加了使用标签的屏幕截图,以显示console.log可能不会说什么。

firebase google-cloud-firestore google-cloud-functions
1个回答
3
投票

由于您的功能仪表板显示触发器“ref.write”,这意味着当您写入实时数据库而不是Cloud Firestore时会触发您的云功能。它们是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;
  });
© www.soinside.com 2019 - 2024. All rights reserved.