firebase - 结构 Firebase 数据

标签 firebase firebase-realtime-database nosql

我如何在 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/

相关文章:

firebase - Firebase 服务器上的时间戳计算

ios - Firebase、 swift : Create a time checker in the background similar to the Snapchat streak system that performs an action when the time runs out

java - 调用 Firebase recyclerview 查询的语法

content-management-system - 使用 Clojure 进行 Web 开发的 SQL 与 NO-SQL

android - linkWithCredential 是如何工作的?它如何与规则一起使用?

python - Firebase Python firestore.DELETE_FIELD 在 VS Code 中显示为错误

javascript - Firebase 实时数据库值事件期间传输的数据

database - 寻找不在内存中且具有 "list,set"数据类型的键值数据库

couchbase - Couchbase 的数据迁移文档(即更改现有字段类型)?

javascript - Firebase API 不响应使用 Axios on react native 的常见错误代码