1
My Firebase looks like this:
- widgets
  - abc123abc
    - key1: val1
    - key2: val2
    - key3: val3
    - ...
  + abc123abd
  + ...
- widgets-index
  - abc123abc
    - timestamp: 1289183274834
  - abc123abd
    - timestamp: 1289183274834

I am storing a collection of widget objects and simultaneously keeping a separate list of their indices. When I fetch data from a selected object using a view of indices, I need to obtain a subset of the data object's properties.

I read somewhere that Firebase uses web sockets so I should not worry about the performance cost of multiple fetches? Did I understand that correctly?

At what point should I store the entire subset of object properties at the widgets-index node instead of making a separate call to /widgets?

Edit:

The solution to this problem can be found here.

4

1 回答 1

1

Firebase 实时数据库支持任意复杂的原子深度更新(博客文章)。它是这样工作的:

您可以使用单个 .update() 调用来更新任意深度的路径更新映射的键侧的完整路径将被替换,因此如果您不想吹走父路径,则必须直接寻址子键路径是相对的到您当前的参考所以让我们举个例子:

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);

这将同时更新所有位置。要使其动态化,只需在构造键时使用字符串插值。

免责声明:此答案从此处复制。最初回答者:@Michael Bleigh

于 2018-02-21T11:25:59.813 回答