【问题标题】:What is the JSON format for a firestore composite index including an array?包含数组的 Firestore 复合索引的 JSON 格式是什么?
【发布时间】:2019-04-03 21:44:45
【问题描述】:

我想在一个列(比如keywords)上使用array-contains 过滤一个集合(我们称之为documents)并按另一列排序(比如name)。

我可以在 firebase 控制台中创建此复合索引,但我只能猜测将其添加到 firestore.indexes.json 的格式。

很遗憾,我们无法从控制台下载索引文件。

【问题讨论】:

    标签: firebase google-cloud-firestore


    【解决方案1】:

    将模式设置为 ARRAY_CONTAINS:

    {
          "collectionId": "documents",
          "fields": [
            {
              "fieldPath": "keywords",
              "mode": "ARRAY_CONTAINS"
            },
            {
              "fieldPath": "name",
              "mode": "ASCENDING"
            }
      ]
    }
    

    您还可以在 Firebase CLi 中以 JSON 格式 list your current Cloud Firestore indexes

    firebase firestore:indexes
    

    【讨论】:

    • 太棒了,希望我能给你每个部分的分数。我会从控制台猜到 ARRAY,而我的第二个猜想是 API 中的 ARRAY-CONTAINS。
    • 添加 firebase 命令以从 CLI 下载索引文件的工作非常棒!
    • 对我来说,在导出集合组索引时,这是在导出错误的格式化程序 json。命令行忘记关闭索引上的数组通知器:
    • M. V. P. 你会认为谷歌搜索会很容易找到这个信息,但我们在这里。感谢您提供 CLI 命令。
    【解决方案2】:

    导出 Firestore 索引

    firebase firestore:indexes > firestore.indexes.json
    

    小心!这将替换 firestore.indexes.json 中的所有内容。

    或者,如果您的 .firebaserc 中有多个 firebase 项目:

    "projects": {
        "production": "prod-v6909",
        "staging": "prod-c6020"
    }
    

    然后你可以像这样导出:

    firebase --project staging firestore:indexes > firestore.indexes.json
    

    【讨论】:

      【解决方案3】:

      您还可以从以下位置以 JSON 格式列出您当前的 Cloud Firestore 索引 Firebase CLi:firebase firestore:indexes

      对我来说,在导出集合组索引时,这是在导出错误的格式化程序 json。命令行忘记关闭索引上的数组通知器:

      {
        "indexes": [],
        "fieldOverrides": [
          {
            "collectionGroup": "restaurants_users_config",
            "fieldPath": "user",
            "indexes": [
              {
                "order": "ASCENDING",
                "queryScope": "COLLECTION"
              },
              {
                "order": "DESCENDING",
                "queryScope": "COLLECTION"
              },
              {
                "arrayConfig": "CONTAINS",
                "queryScope": "COLLECTION"
              },
              {
                "order": "ASCENDING",
                "queryScope": "COLLECTION_GROUP"
              }
          }
        ]
      }
      

      有什么建议吗?只手动修复json数组对吗?

      **编辑 修复:已通过 firebase 升级 8.2.0 → 8.4.1 修复

      【讨论】:

        猜你喜欢
        • 2019-10-19
        • 2018-03-30
        • 1970-01-01
        • 2014-10-13
        • 1970-01-01
        • 1970-01-01
        • 2020-10-20
        • 1970-01-01
        • 2015-02-21
        相关资源
        最近更新 更多