更新Firebase中的所有子级 [英] Update all child in Firebase

查看:98
本文介绍了更新Firebase中的所有子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firebase的数据库中,我需要更新open的值并将其传递给所有子级的false.我如何用Java语言做到这一点? 像这样

In a database from Firebase, I need to update the value open and pass it to false for all child. How I can do it in Javascript ? Something like this

let dbCon = firebase.database().ref("/messages/" + *);
    dbCon.update({
      open: false
    });

推荐答案

Firebase数据库没有等效于SQL的UPDATE messages SET open=false.

The Firebase Database has no equivalent to SQL's UPDATE messages SET open=false.

要更新Firebase中的节点,必须首先具有对该特定节点的引用.为了获得对节点的引用,您必须知道该节点的完整路径.

To update a node in Firebase, you must first have a reference to that specific node. And to get a reference to a node, you must know the full path to that node.

这意味着您首先需要读取数据,然后循环遍历,然后依次更新每个子级.在代码中:

This means that you'll first need to read the data, then loop over it, and then update each child in turn. In code:

let dbCon = firebase.database().ref("/messages/");
dbCon.once("value", function(snapshot) {
  snapshot.forEach(function(child) {
    child.ref.update({
      open: false
    });
  });
});

这篇关于更新Firebase中的所有子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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