【问题标题】:How to use multiple index.js files/cloud functions on firestore functions如何在 firestore 函数上使用多个 index.js 文件/云函数
【发布时间】:2022-10-14 18:11:33
【问题描述】:

我有一个云函数,它正在检查计数值,它是文档中的一个字段,该字段位于“男孩”集合中。在计数发生变化时,云函数会执行一些操作。 我想要一个类似的云功能,但另一个名为“女孩”的集合。我现在如何将另一个功能部署到云功能,它只是让我通过替换旧功能来上传一个?

exports.updatingCount = functions.firestore
  .document('boys/{count}')
  .onWrite((snap) => {//The current function with my code here})

我想要一个类似的功能,但找不到如何获得它。

【问题讨论】:

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


    【解决方案1】:

    您可以为女孩创建具有不同名称的相同 Cloud Function:

    exports.updatingCountForGirls = functions.firestore
      .document('girls/{count}')
      ...
    

    或者,您可以采用完全可变路径的更灵活的方法:

    exports.updatingCount = functions.firestore
      .document('{collectionPath}/{count}')
      ...
    

    并检查云函数中collectionPath 的值。

    【讨论】:

    • 是的,我已经解决了,但非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-04
    • 2018-03-28
    • 2023-03-07
    • 2019-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多