How do I write/update data to multiple child nodes via Firebase Cloud functions?

前端 未结 2 1402
暗喜
暗喜 2020-12-22 02:26

I\'ve got a database that looks like this:

I want to reset the Patient_List and Current_Token children to 0 at a particular time (

相关标签:
2条回答
  • 2020-12-22 03:00

    It's not possible to have a single update statement affect a child of all database nodes under some location. You will have to iterate all the nodes (by querying/reading them somehow), then update each one that you find. This is potentially a costly operation in terns of bandwidth.

    0 讨论(0)
  • 2020-12-22 03:14

    Only use the general ref, and before that reference all nodes that you want to update, just like this:

    var gralRef = firebase.database().ref();
    var obj_update={};                              
    obj_update[`users/${firstuser}/name`]='John';
    obj_update[`users/${seconduser}/name`]='Mark';
    obj_update[`users/${seconduser}/address`]='New York';   
    
    
    gralRef.update(obj_update);                     
    
    0 讨论(0)
提交回复
热议问题