适用于Firebase的Cloud Functions:从数据库检索创建子项的日期 [英] Cloud Functions for Firebase: retrieve the date of creation of a child from the database

查看:50
本文介绍了适用于Firebase的Cloud Functions:从数据库检索创建子项的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个函数,该函数运行某个节点上的所有子节点,以对x天前刚创建的子节点执行某些操作.我已经在服务器上创建了一个cron,每天调用一次该函数.我的问题是我找不到如何迭代节点中的所有子代并知道其创建日期的方法.是否有执行此操作的功能,或者我必须在字段中添加创建日期?

I'm trying to make a function that runs all the children from a certain node to perform something on those that were created exactly x days ago. I have already created a cron on my server to call the function once a day. My problem is that I do not find how to iterate all the children from a node and know their creation date. Is there a function to do this or do I have to put a field with the creation date?

推荐答案

向每个节点添加时间戳(创建日期)子级.

Add a timestamp (creation date) child to each node.

parent_node
    node_0
      timestamp: "20170328"
    node_1
      timestamp: "20170329"
    node_2
      timestamp: "20170330"

然后使用.childAdded事件遍历parent_node的所有子节点,或者如果节点数较少,则使用.value加载所有的孩子并在代码中进行迭代.

Then iterate over all the children of parent_node with .childAdded events or if it's a smaller number of nodes, use .value to load all of the children and iterate in code.

这篇关于适用于Firebase的Cloud Functions:从数据库检索创建子项的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆