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

Vee*_*ddy 5 database indexing firebase google-cloud-firestore

请让我知道如何在 firebase-indexes.json 文件中添加单字段的索引豁免,以便通过 CLI 进行部署。

目前,下面是我在文件 firebase-indexes.json 中的索引配置,可以通过 CLI 部署,但它正在创建复合类型的索引,而不是作为单字段豁免。

{
  "indexes": [
    {
      "collectionGroup": "comments",
      "queryScope": "COLLECTION",
      "fields": [
        {
          "fieldPath": "id",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "id",
          "order": "DESCENDING"
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

提前致谢。

Dou*_*son 6

假设您的集合称为“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"
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)