Firebase How to update multiple children?

后端 未结 1 1453
死守一世寂寞
死守一世寂寞 2021-02-15 05:48

I have parent with many children like this:

 Parent:{
        \"childe1\":\"data\",
        \"childe2\":\"data\",
        \"childe3\":\"data\",
        \"childe4         


        
相关标签:
1条回答
  • 2021-02-15 06:29

    To update multiple properties at the same time, you can run an update() call:

    ref.child("Parent").update({
      childe1: "newdata",
      childe2: "newdata",
      childe3: "newdata"
    });
    

    You can even specify paths as the keys, in case the properties are at different levels in the tree. Even though that doesn't seem to be the case here, the syntax would be:

    ref.update({
      "Parent/childe1": "newdata",
      "Parent/childe2": "newdata",
      "Parent/childe3": "newdata"
    });
    

    The exact validation depends a bit on what you'd like to allow, but in general you'd write .validate rules on the server that validate that newData meet your requirements.

    0 讨论(0)
提交回复
热议问题