Firebase - tiered update method is deprecated, now what?

I had several apps that used the multi-location update method like below:

const updates = [];
updates['/location1'] = data;
updates['/location2'] = data2;

firebase.database().ref().update(updates);

      

However, when I develop a new application, I got the following message:

FIREBASE WARNING: Passing an Array to Firebase.update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.

Without any real information on how to do atomic updates with multiple locations anywhere, and the docs are still with the old method. Chaining is then()

not a good idea as it would be a rollback nightmare.

Any hints and / or information on new methods for updating multiple locations?

+3


source to share


1 answer


I didn't even know that you can pass an array. You must pass an object instead:

const updates = {}; // this line is different
updates['/location1'] = data;
updates['/location2'] = data2;

firebase.database().ref().update(updates);

      



The array syntax we use to set properties also works on a JavaScript object.

+7


source







All Articles