当前位置: 首页 > 知识库问答 >
问题:

什么是Firebase云FireStore中的反正规化?

戈念
2023-03-14

共有1个答案

斜博超
2023-03-14

什么是Firebase云FireStore中的反正规化?

反规范化不仅仅与云Firestore相关,而是NoSQL数据库中普遍使用的技术。

什么是真正的非正规化?

Firestore-root
    |
    --- questions (collections)
          |
          --- questionId (document)
                 |
                 --- questionId: "LongQuestionIdOne"
                 |
                 --- title: "Question Title"
                 |
                 --- tags (collections)
                      |
                      --- tagIdOne (document)
                      |     |
                      |     --- tagId: "yR8iLzdBdylFkSzg1k4K"
                      |     |
                      |     --- tagName: "History"
                      |     |
                      |     --- //Other tag properties
                      |
                      --- tagIdTwo (document)
                            |
                            --- tagId: "tUjKPoq2dylFkSzg9cFg"
                            |
                            --- tagName: "Geography"
                            |
                            --- //Other tag properties

我们可以通过简单地将tags集合移动到一个单独的顶级集合中来扁平化数据库,如下所示:

Firestore-root
    |
    --- questions (collections)
    |     |
    |     --- questionId (document)
    |            |
    |            --- questionId: "LongQuestionIdOne"
    |            |
    |            --- title: "Question Title"
    |
    --- tags (collections)
          |
          --- tagIdOne (document)
          |     |
          |     --- tagId: "yR8iLzdBdylFkSzg1k4K"
          |     |
          |     --- tagName: "History"
          |     |
          |     --- questionId: "LongQuestionIdOne"
          |     |
          |     --- //Other tag properties
          |
          --- tagIdTwo (document)
                |
                --- tagId: "tUjKPoq2dylFkSzg9cFg"
                |
                --- tagName: "Geography"
                |
                --- questionId: "LongQuestionIdTwo"
                |
                --- //Other tag properties

现在,要获得与特定问题对应的所有标记,只需查询tags集合,其中QuestionID属性保存所需的问题ID。

或者,您可以同时对数据库进行扁平化和非规范化,如以下模式所示:

Firestore-root
    |
    --- questions (collections)
    |     |
    |     --- questionId (document)
    |            |
    |            --- questionId: "LongQuestionIdOne"
    |            |
    |            --- title: "Question Title"
    |            |
    |            --- tags (collections)
    |                 |
    |                 --- tagIdOne (document) //<----------- Same tag id
    |                 |     |
    |                 |     --- tagId: "yR8iLzdBdylFkSzg1k4K"
    |                 |     |
    |                 |     --- tagName: "History"
    |                 |     |
    |                 |     --- //Other tag properties
    |                 |
    |                 --- tagIdTwo (document) //<----------- Same tag id
    |                       |
    |                       --- tagId: "tUjKPoq2dylFkSzg9cFg"
    |                       |
    |                       --- tagName: "Geography"
    |                       |
    |                       --- //Other tag properties
    |
    --- tags (collections)
          |
          --- tagIdOne (document) //<----------- Same tag id
          |     |
          |     --- tagId: "yR8iLzdBdylFkSzg1k4K"
          |     |
          |     --- tagName: "History"
          |     |
          |     --- questionId: "LongQuestionIdOne"
          |     |
          |     --- //Other tag properties
          |
          --- tagIdTwo (document) //<----------- Same tag id
                |
                --- tagId: "tUjKPoq2dylFkSzg9cFg"
                |
                --- tagName: "Geography"
                |
                --- questionId: "LongQuestionIdTwo"
                |
                --- //Other tag properties
    null
 类似资料:
  • 我只是在探索新的Firebase Firestore,它包含一个名为的数据类型。我不清楚这有什么作用。 像外键吗? 它是否可用于指向位于其他位置的集合? 如果是实际引用,我可以使用它进行查询吗?例如,我可以有一个直接指向用户的引用,而不是将userId存储在文本字段中吗?可以使用此用户引用进行查询吗?

  • 我有一个具有以下安全规则的云Firestore数据库:

  • 我按顺序调用这些函数(javascript'Firebase'): 我在firestore中设置了安全规则,只有当文档中的电子邮件字段等于auth email:时,才允许读取“users/:docid” 问题是在上会出现权限缺失或不足的错误。当然,数据库中的电子邮件是正确的,所以唯一的问题可能是无效。是否登录(使用任何登录函数),即使解析,也不能保证auth令牌被更新并可以立即使用?

  • 我正在开发一款iOS应用程序,它有(哇,惊喜!)聊天功能。整个应用程序大量使用Firebase工具,对于数据库,我正在使用新的云Firestore解决方案。 目前我正在使用数据库规则加强安全性,但我对自己的数据模型有点挣扎:)这可能意味着我的数据模型选择不当,但我真的很满意,除了实现规则部分。 模型的对话部分如下所示。在我的数据库的根目录下,我有一个集合: 然后我对每个对话都有一个子集合,称为消息

  • null 基本上数据结构如下所示: 问题是,我应该写什么安全规则来允许用户只在他们所属的组中(拥有组密钥)读取、创建和更新数据?同时,如何禁止用户找出其他群组的密钥?

  • 最近我收到了一系列Firebase通知,涉及: [Firebase]您的Cloud FiRecovery数据库有不安全的规则 我们检测到您的安全规则存在以下问题:任何用户都可以写入您的整个数据库。因为您的项目没有强大的安全规则,任何人都可以访问您的整个数据库。攻击者可以窃取、修改或删除您的数据,并会抬高您的账单` Edit2:我需要的是允许每个人都写,而不需要登录,但是只有管理员帐户应该能够从Fi