Cloud features for Firebase multipath update

I am trying to migrate a multiple path update that I previously created in my Android client earlier to a cloud function.

For my application, a user can send a message (in "messages") that is associated with a car ("Cars"), for example a Porsche 911.

When a user posts a new message (β€œmessages”), I would like to update the popularity of the corresponding vehicle in the β€œCars” data, as well as all other vehicle messages associated with the same vehicle.

However, when I run different versions of the js code as a cloud function, it doesn't iterate over my "carPosts" data to create paths to each post that needs to be updated.

Can anyone help me with the required js code for the cloud function?

enter image description here

  • on new post enter car key - i can get this to work

  • update the popularity of the car, increasing the current popularity by 1 - I can get this to work

  • update all car messages related to the vehicle related to the new message? This does not work?

    var updKeys = {
    
            ["posts/-KIL0lbjplFBijxAJ75U/car/popularity"]: '1060',
    
            ["posts/-KIL0zBcU3Hjx6gf4Gxk/car/popularity"]: '1060',
    
            ["posts/-KIL1Wv6elvpf3T-0FVK/car/popularity"]: '1060',
    
            ["posts/-KIL2kUvY62qi46hb2t3/car/popularity"]: '1060',
        }
    
          

+3


source to share


1 answer


You will need to use the update

Firebase function . Something like below

ref.child('posts/${pushid}/car).update({popularity:1060})

      



This should automatically update all relevant posts. But you might have to handle events Promises

and subsequent ones onWrite

.

0


source







All Articles