【问题标题】:How can I have multiple Firebase Database listeners and `exports.pushNotification` in Firebase Functions如何在 Firebase 函数中拥有多个 Firebase 数据库侦听器和“exports.push Notification”
【发布时间】:2021-09-07 07:59:46
【问题描述】:

我有一个监听器,当 Firebase 实时数据库发生变化时会推送通知。

exports.pushNotification = functions.database
    .ref("/Currency/Price")
    .onWrite((change, context) => { ... }

我尝试只复制上面显示的相同函数并更改数据库引用,但它最终忽略了第一个,因此只有第二个数据库引用推送通知,而不是第一个。

如何为实时数据库中的另一条记录添加另一个侦听器和推送通知?

【问题讨论】:

    标签: node.js firebase firebase-realtime-database push-notification google-cloud-functions


    【解决方案1】:

    如果你想声明两个不同的 Cloud Functions 应该在同一个数据库位置(即节点)触发,只需使用另一个名称,如下所示:

    exports.pushNotification1 = functions.database
        .ref("/Currency/Price")
        .onWrite((change, context) => { ... }
    
    exports.pushNotification2 = functions.database
        .ref("/Currency/Price")
        .onWrite((change, context) => { ... }
    

    如果要在另一个位置声明另一个函数,只需执行以下操作:

    exports.pushNotification1 = functions.database
        .ref("/Currency/Price")
        .onWrite((change, context) => { ... }
    
    exports.pushNotification2 = functions.database
        .ref("/abcd/efgh")
        .onWrite((change, context) => { ... }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 1970-01-01
      • 2018-02-12
      相关资源
      最近更新 更多