我如何在 firebase 中构建数据来检索当前用户尚未评论的所有帖子。我对 nosql 非常陌生,似乎无法摆脱 SQL 的结构方式。
这是我的尝试:
Posts: {
someUniqueId: {
user: userid,
content: "blah"
}
}
Comments: {
someCommentUniqueId: {
comment: "ola",
post: someUniqueId,
user: userid
}
}
现在,如果上述是正确的,我完全不知道如何查询这个。在 NOSQL 中是否可能?
最佳答案
Firebase 没有查询值是否缺失的机制。请参阅is it possible query data that are not equal to the specified condition?
在 NoSQL 中,您通常最终会为所需的查询建模数据。因此,如果您想知道每个用户仍然可以评论哪些帖子,请在 JSON 树中对该信息进行建模:
CommentablePosts_per_User
$uid
$postid: true
这种类型的结构通常称为索引,因为它允许您有效地查找给定用户的相关 $postid
值。从数据中提取此类索引的过程通常称为非规范化。有关此技术(有点旧)的概述,请参阅此 Firebase blog post on denormalization .
我推荐这篇文章很好introduction to NoSQL data modeling .
关于firebase - 结构 Firebase 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35106849/