Skip to content Skip to sidebar Skip to footer

Update All Child In Firebase

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(

Solution 1:

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

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
    });
  });
});

Post a Comment for "Update All Child In Firebase"