javascript - Update all child in Firebase - Stack Overflow

In a database from Firebase, I need to update the value open and pass it to false for all child. How I

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

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

Share Improve this question edited Apr 8, 2018 at 14:33 Frank van Puffelen 600k85 gold badges890 silver badges860 bronze badges asked Apr 8, 2018 at 11:18 Monsieur SamMonsieur Sam 3331 gold badge7 silver badges20 bronze badges 3
  • Update your state through a for loop or so? Your state should be synced to Firebase? – Satej S Commented Apr 8, 2018 at 11:25
  • I edit it to explain, yes it have to be synced to firebase – Monsieur Sam Commented Apr 8, 2018 at 11:28
  • 1 Check out github./tylermcginnis/re-base – Satej S Commented Apr 8, 2018 at 11:44
Add a ment  | 

1 Answer 1

Reset to default 12

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743909317a4528062.html

相关推荐

  • javascript - Update all child in Firebase - Stack Overflow

    In a database from Firebase, I need to update the value open and pass it to false for all child. How I

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信