【问题标题】:Querying a list in Firebase Firestore在 Firebase Firestore 中查询列表
【发布时间】:2018-01-08 16:54:01
【问题描述】:

我在我的项目中使用 Firebase Firestore 数据库。我的数据结构如下:

  • 用户(集合)
    • user1(文档)
      • followingPeople(数组)
        • 0
          • person0
        • 1
          • person1
        • 2
          • person2
        • 3
          • person3
    • user2(文档)
      • followingPeople(数组)
        • 0
          • person0
        • 1
          • person1

我需要编写一个查询,在文档字段的以下人员部分中查找具有特定人员的用户。

例如,如果我查询跟随 person0 的用户,根据我上面的示例将返回 user1 和 user2。

任何建议将不胜感激。

【问题讨论】:

    标签: swift firebase google-cloud-firestore


    【解决方案1】:

    将followingPeople 存储在数组中是一种反模式。请阅读Firestore documentation on working with arrays, lists and sets 以获得更好的方法。

    followingPeople: {
        "person0": true,
        "person1": true,
        "person2": true
    }
    

    我还建议阅读我对http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value 的回答。虽然它是为 Firebase 实时数据库编写的,但同样的逻辑也适用于此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-07
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      相关资源
      最近更新 更多