首页 > 解决方案 > How to listen for added nodes in the firebase database

问题描述

I know how to read data from the firebase database, in my database structure, there is a child with various nodes written and pushed by users. How can I add a listener that will tell me whenever a new node has been added in the child and trigger a notification. Please note I already have a method for creating a notification. I don't want to know the contents of the child added, I just want to know whenever a new child is added. How would I go about this?

标签: javafirebasefirebase-realtime-database

解决方案


对于此功能,您需要将 Firebase函数数据库触发器一起使用

您可以在此处查看此功能的示例

基本上它是如何工作的

  • 你写一个函数(打字稿/javascript)
  • 您将该函数部署到 Firebase 函数中由于您在函数中使用了数据库触发器,因此只要在您正在侦听的节点内插入新项目,该函数就会触发
  • 触发器是 onCreate()
  • 您将制作一个通知负载,该负载将发送到您存储在子节点中的用户设备令牌

推荐阅读