Firebase How to update multiple children?

与世无争的帅哥 提交于 2019-12-09 11:57:50

问题


I have parent with many children like this:

 Parent:{
        "childe1":"data",
        "childe2":"data",
        "childe3":"data",
        "childe4":"data",
        "childe5":"data"
 }

How can I update the children [ childe1 , childe2 , childe3 ] at same time, preventing any other user from updating them at same time?


回答1:


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.



来源:https://stackoverflow.com/questions/40878551/firebase-how-to-update-multiple-children

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!