Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase - Multi-location updates method deprecated, what now?

I had some apps that used the multi-location update method as below:

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

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

Yet, as I'm developing a new app, 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.

With no real info anywhere about how to perform multi-location atomic updates anywhere, and the docs are still with the old method. Chaining then() is not a good idea, as it would be a nightmare to rollback.

Any clues and/or information on new multi-location updates methods?

like image 632
jacques mouette Avatar asked Jun 08 '17 20:06

jacques mouette


People also ask

Which method used to update the Firebase data?

For updating a single node in our JSON database, we simply use setValue() on the correct child reference.

How can you specify what place to update in Firebase real time database?

If you want to allow users to update their profiles you could update the username as follows: FirebaseDatabase database = FirebaseDatabase. getInstance(); DatabaseReference mDatabaseRef = database. getReference(); mDatabaseRef.

What is the set () method in Firebase?

The set method will write or replace data on a specified path. Let us create a reference to the player's collection and set two players. var playersRef = firebase. database(). ref("players/"); playersRef.

What is the difference between set and update in Firebase?

In RESTful terms “set” is like an PUT, and an “update” is like a PATCH, but there is a bit more interesting distinctions under the covers. Firebase… pirate…. PATCH… get it?


Video Answer


1 Answers

I didn't even know you could pass an array. You should instead pass an object:

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

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

The array syntax we use for setting properties works on a JavaScript object too.

like image 106
Frank van Puffelen Avatar answered Oct 12 '22 18:10

Frank van Puffelen