【问题标题】:Firebase functions how can I listen for a different child 1 time for onWrite when triggered?Firebase函数如何在触发时为onWrite监听不同的孩子1次?
【发布时间】:2021-07-23 08:28:25
【问题描述】:

如何在每次触发 Firebase 函数 onWrite 时在不同节点下监听子节点

这个孩子 = {const saatt = (context.database .ref('kullanicilar/1111/marina1/2021/1saat').once('value')).val();}

exports.pushNotification = functions.database.ref('kullanicilar/1111/marina1/realtime/control')
    .onWrite((Change,context) =>{
        var oldDeger = Change.before.val();
        var newDeger = Change.after.val();
        
        
    
        if (newDeger > oldDeger){
          const saatt = (context.database
            .ref('kullanicilar/1111/marina1/2021/1saat').once('value')).val();
            if (saatt === 0){
                database.ref('kullanicilar/1111/marina1/realtime/ufuk').set('tamm');
    
            }
        
        }
       
    });

【问题讨论】:

  • 请分享你的数据库结构截图,他说明你想在哪个节点触发函数
  • 我建议您查看 Cloud Functions for the Realtime Database 文档中专用于 path 的部分。

标签: javascript node.js google-cloud-functions


【解决方案1】:

您需要使用通配符来匹配多个路径。我无法真正理解您当前的路径,但让我们这样说吧:

//functions.database.ref('kullanicilar/1111/marina1/realtime/control')

functions.database.ref('kullanicilar/{thisId}/marina1/realtime/control')

现在,您的函数将在与他的模式匹配的所有路径上触发。我上面 thisId 的示例值可以是任何值。同样,您可以添加更多通配符。

【讨论】:

  • onwrite 工作正常它正在触发我想听 saat1 孩子
  • @ufuksipor 请分享数据库截图。听你的意思是读一次价值吗?因为您不应该在 Cloud 函数中使用 realtimr 侦听器
  • 如果条件满足,我想读1saat child 1次。
  • const saatt = (context.database .ref('kullanicilar/1111/marina1/2021/1saat').once('value')).val(); if (saatt === 0){ database.ref('kullanicilar/1111/marina1/realtime/ufuk').set('tamm'); }
猜你喜欢
  • 1970-01-01
  • 2018-05-16
  • 2020-08-24
  • 1970-01-01
  • 1970-01-01
  • 2018-08-02
  • 2018-10-11
  • 2017-08-25
  • 1970-01-01
相关资源
最近更新 更多