How to insert data into Firebase using Polymerfire (mutiple nodes + multiple paths)

馋奶兔 提交于 2019-12-01 00:46:11

The Firebase Realtime Database supports arbitrarily complex atomic deep updates (blog post). It works like so:

  1. You can update any arbitrarily deep path with a single .update() call
  2. The full path on the key side of your update map will be replaced, so you must address subkeys directly if you don't want to blow away the parent
  3. Paths are relative to your current ref

So let's take your example:

var update = {};

update['emails/email3@example,com'] = {new: 'data'};
update['emails/email4@example,com'] = {new: 'data'};
update['users/c0djhbQi6vc4YMB-fDgJ/emails/email3@example,com'] = {new: 'data'};
update['users/c0djhbQi6vc4YMB-fDgJ/emails/email4@example,com'] = {new: 'data'};

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

This will update all of the locations simultaneously. To make it dynamic, simply use string interpolation when constructing the keys.

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