【发布时间】:2015-10-13 07:37:25
【问题描述】:
我认为我已经将非规范化作为一种主要的优化方法,将数据存储在 Firebase 中,如this one 和此blog post 等问题中提到的,但我陷入了一个小细节。
假设我的域中有两个东西,用户和帖子,如我提到的blog article,我可能有 20,000 个用户和 20,000 个帖子。因为我像一个好孩子一样对一切进行了非规范化,root/users/posts 和root/posts 一样存在。 root/users/posts 有一组值为 true 的 post 键,因此我可以获得用户的所有 post 键。
users: {
userid: {
name: 'johnny'
posts: {
-Kofijdjdlehh: true,
-Kd9isjwkjfdj: true
}
}
}
posts: {
-Kofijdjdlehh: {
title: 'My hot post',
content: 'this was my content',
postedOn: '3987298737'
},
-Kd9isjwkjfdj: {
title: 'My hot post',
content: 'this was my content',
postedOn: '3987298737'
}
}
现在,我想列出用户发布的所有帖子的标题。我不想为了获得标题而加载所有 20,000 个帖子。我只能想到以下选项:
使用
root/users/posts路径中设置为true的键子集以某种方式查询root/posts路径(如果可能,我还没有弄清楚如何)-
将标题存储在
root/users/posts中,以便该路径中的每个条目都具有重复的标题,如下所示:posts: { -Kofijdjdlehh: true }变成
posts: { -Kofijdjdlehh: { title: 'This was my content' } }这似乎是合理的,但我还没有看到一个这样做的例子,所以我担心这是一些反模式。
我找不到的另一种方式
感谢您提供的关于此用例的任何建议或我可能遗漏的文档。
【问题讨论】:
标签: firebase