【问题标题】:How to query two values inside an array in Firebase firestore, where one value is indexed after the other one?如何在 Firebase Firestore 中查询数组中的两个值,其中一个值在另一个值之后被索引?
【发布时间】:2020-11-18 20:45:36
【问题描述】:

有什么方法可以查询 firebase firestore 中的字符串值数组,该数组应包含两个字符串 ab 但字符串 b必须在字符串 a 之后列出?

示例: 我有两个要查询的字符串值:

a = "12345"
b = "67890"

我在 firebase firestore 中存储了多个文档,如下所示:

document1 = {
    id: "randomId1",
    // ...other stuff
    array: ["12345","345", "67890"]
}

document2 = {
    id: "randomId2",
    // ...other stuff
    array: ["67890","345","12345"]
}

现在我只想在查询结果中获取 document1,因为值 b 列在数组部分中的值 a 之后。我该怎么做?

【问题讨论】:

    标签: javascript firebase google-cloud-firestore


    【解决方案1】:

    在firestore中没有办法做这样的查询,你只能定义它是否有这个值。

    可能的解决方案:

    1. 在您的文档中存储一个布尔值,用于定义该文档是否适合您的需求。
    2. 加载具有这两个值的所有文档并在客户端检查它们的顺序。
    3. 或许您应该重组您的数据库,在这种情况下通常会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-11
      • 2015-02-21
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 2018-11-29
      相关资源
      最近更新 更多