【问题标题】:Getting AutoKey with Firebase Function使用 Firebase 功能获取 AutoKey
【发布时间】:2017-08-04 21:08:23
【问题描述】:

我正在尝试使用 firebase 功能获取自动密钥。

event.data.key 不返回密钥。我如何监听 isEnabled,当它更改为 true 时,使用相同的键向通知引用添加另一个数据。

exports.sendNotificationWhenEnabled = functions.database.ref('/contents/{contentId}/isEnabled').onWrite(event => {
  const isEnabled = event.data.val();
  const contentId = event.data.key;
  admin.database().ref('/contents/' + contentId).once('value', function(snapshot) {
      console.log('Sending Notification to: ', contentId);
      admin.database().ref('/notifications/' + contentId).push({
        'asd': 'asd'
      }).then(snapshot => {
        console.log('finished');
      });
    });
    return "FINISHED";
  }
});

【问题讨论】:

  • 使用const contentId = event.data.ref.key;。见firebase.google.com/docs/functions/…
  • 感谢您的帮助。而且我还找到了另一个解决方案 event.params.contentId
  • 很高兴听到您找到了解决方案。

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


【解决方案1】:

我找到了 event.params.contentId 的解决方案

【讨论】:

    猜你喜欢
    • 2020-07-26
    • 1970-01-01
    • 1970-01-01
    • 2020-02-28
    • 2020-05-30
    • 2019-10-17
    • 2021-04-11
    • 1970-01-01
    • 2020-03-03
    相关资源
    最近更新 更多