如何通过 Firebase Cloud 功能将数据写入/更新到多个子节点? [英] How do I write/update data to multiple child nodes via Firebase Cloud functions?

查看:18
本文介绍了如何通过 Firebase Cloud 功能将数据写入/更新到多个子节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的数据库:

I've got a database that looks like this:

我想在特定时间(比如上午 12 点)为数据库中的所有用户自动将 Patient_ListCurrent_Token 子项重置为 0.

I want to reset the Patient_List and Current_Token children to 0 at a particular time (say 12 AM) automatically for all the users in the database.

我浏览了 Firebase 云函数文档和 gitHub 上的这些项目:删除节点删除未使用的使用 Cron 的用户帐户.上述两个示例都基于特定的 UID 更新和更改数据,即仅基于传递的 UID 更新特定节点.我想知道是否可以更新所有节点中上述子元素的值,如果可以,如何完成?

I went through the Firebase cloud function docs and these projects on gitHub: Deleting nodes and Delete unused user accounts using Cron. Both of the above examples update and change data based on a particular UID i.e update only particular nodes based on the UID passed. I would like to know if it is possible to update values for the above child elements in all the nodes and if so , how would it be done?

推荐答案

只使用通用 ref,在此之前引用你要更新的所有节点,就像这样:

Only use the general ref, and before that reference all nodes that you want to update, just like this:

var gralRef = firebase.database().ref();
var obj_update={};                              
obj_update[`users/${firstuser}/name`]='John';
obj_update[`users/${seconduser}/name`]='Mark';
obj_update[`users/${seconduser}/address`]='New York';   


gralRef.update(obj_update);                     

这篇关于如何通过 Firebase Cloud 功能将数据写入/更新到多个子节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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