更新Firebase中的所有子级 [英] Update all child in 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屋!