简体   繁体   English

如何在 Firestore 索引配置文件中添加单字段豁免

[英]How to add Single-field Exemptions in Firestore Index Config File

Please let me know how to add Index exemptions for Single-field, in the firebase-indexes.json file, in order to deploy through CLI.请让我知道如何在 firebase-indexes.json 文件中为单字段添加索引豁免,以便通过 CLI 进行部署。

Currently, below is my index config in the file firebase-indexes.json, able to deploy through CLI, but it is creating an index of type Composite, not as a Single-field Exemption.目前,下面是我在文件 firebase-indexes.json 中的索引配置,能够通过 CLI 进行部署,但它正在创建复合类型的索引,而不是作为单字段豁免。

{
  "indexes": [
    {
      "collectionGroup": "comments",
      "queryScope": "COLLECTION",
      "fields": [
        {
          "fieldPath": "id",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "id",
          "order": "DESCENDING"
        }
      ]
    }
  ]
}

Thanks in advance.提前致谢。

Assuming that your collection is called "comments" and your exemption field is called "field", you will add a new property to your firestore.indexes.json called "fieldOverrides", like this:假设您的集合称为“comments”并且您的豁免字段称为“field”,您将向 firestore.indexes.json 添加一个名为“fieldOverrides”的新属性,如下所示:

{
  "indexes": [
    // your indexes here
  ],
  "fieldOverrides": [
    {
      "collectionGroup": "comments",
      "fieldPath": "field",
      "indexes": [
        {
          "order": "ASCENDING",
          "queryScope": "COLLECTION"
        },
        {
          "order": "DESCENDING",
          "queryScope": "COLLECTION"
        },
        {
          "arrayConfig": "CONTAINS",
          "queryScope": "COLLECTION"
        },
        {
          "order": "ASCENDING",
          "queryScope": "COLLECTION_GROUP"
        },
        {
          "order": "DESCENDING",
          "queryScope": "COLLECTION_GROUP"
        },
        {
          "arrayConfig": "CONTAINS",
          "queryScope": "COLLECTION_GROUP"
        }
      ]
    }
  ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM