【问题标题】:Firebase onWrite Trigger - Disable trigger on updateFirebase onWrite Trigger - 更新时禁用触发器
【发布时间】:2017-10-10 12:46:06
【问题描述】:

我该怎么做?我使用了下面的代码,但它不起作用。当我更新我的数据库时,我仍然会收到通知

exports.sendNewPostNotif = functions.database.ref('/News/{ID}').onWrite(event => {


    const announce_data = event.data.val();
    const announce_data_type = announce_data.categ_post; 
    const announce_data_title = announce_data.title_post; 
    const announce_data_uid = announce_data.uid; id
    const announce_post_key = announce_data.postkey; 

    if(!event.data.val()) {
        return console.log('No data');
    } 

    if(event.data.previous.exist()) {

        return;
    }

每当我发送新内容时,它都会通过 onWrite 事件然后发送通知。我当前的问题是每当我编辑帖子时,它都会发送我不需要的通知。我尝试了上述方法,它可以正常工作,因为我在更新新闻内容时没有收到通知,但在创建新内容时没有收到通知。

【问题讨论】:

标签: android firebase firebase-realtime-database google-cloud-functions


【解决方案1】:

如果您只希望函数在节点创建时运行,而不是在更新或删除时运行,您可以使用onCreate 触发器:

exports.sendNewPostNotif = functions.database.ref('/News/{ID}').onCreate(event => {

请参阅 Firebase documentation on database trigger typesblog post where these are introduced

【讨论】:

  • 不错!谢谢你,弗兰克。
猜你喜欢
  • 2021-04-24
  • 2018-05-16
  • 2019-02-11
  • 1970-01-01
  • 2017-09-25
  • 1970-01-01
  • 2020-08-24
  • 2018-10-11
相关资源
最近更新 更多