0

i am trying to get auto key with firebase functions.

event.data.key doesn't return the key. How can i listen isEnabled and when changed it true, add another data to notification ref with same key.

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";
  }
});
4

1 回答 1

0

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

于 2017-03-14T14:39:25.923 回答