【问题标题】:How to access another array and loop through it in Firebase Functions [duplicate]如何在 Firebase 函数中访问另一个数组并循环遍历它[重复]
【发布时间】:2018-05-15 15:45:02
【问题描述】:

所以在我的 firebase 应用程序中,我想在数据源更新时访问一个数组。

这部分应用运行良好。变量赋值成功。

exports.sendUsersNotification = functions.database.ref('/Groups/{groupId}/messageList/{messageId}/')
.onWrite(event => {
  const original = event.data.val();
  let userId = original['userId']
  let groupId = event.params.groupId;
  let messageId = event.params.messageId;

  const payload = {
    notification: {
      title: 'Messenger',
      body: 'You have a new message'
    }
  };



});

我要访问和循环的数组位于“Groups/{groupId}/listeners”中。

如何访问它?

【问题讨论】:

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


    【解决方案1】:

    Cloud Functions database triggers 只会为您提供数据库中与您在functions.database.ref() 中提供的模式匹配的位置的数据。可以使用Admin SDK查询其他位置的数据库,也可以使用event.data.ref.root建一个Reference到其他位置,使用once()进行查询。在documentationsamples 中有很多这样的例子。

    【讨论】:

    • @BobSnyder 是的,我犯了一个错误,会更正。真的,没有人应该在函数中使用 on()。
    猜你喜欢
    • 2011-08-21
    • 1970-01-01
    • 2018-04-07
    • 2023-03-23
    • 2017-09-12
    • 2018-04-09
    • 2017-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多