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

夙愿已清 提交于 2020-08-24 08:22:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/44444772/firebase-multi-location-updates-method-deprecated-what-now

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