You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Firestore索引部署到指定的非默认数据库?

将Firestore索引部署到非默认数据库的方法

问题描述

我的firestore.indexes.json中有如下索引配置:

"indexes": [
    {
      "collectionGroup": "programsForQuery",
      "queryScope": "COLLECTION",
      "fields": [
        { "fieldPath": "cipCode", "order": "ASCENDING" },
        { "fieldPath": "state", "order": "ASCENDING" },
        { "fieldPath": "sortOrder", "order": "DESCENDING" },
        { "fieldPath": "__name__", "order": "DESCENDING" }
      ]
    }
  ]

执行firebase deploy --only firestore:indexes时,索引会部署到项目的"default" Firestore数据库,但我需要将这些索引部署到名为"national"的第二个数据库,请问如何实现?

解决方案

方法一:部署命令中指定目标数据库

直接在部署命令后添加--database参数,指定目标数据库名称:

firebase deploy --only firestore:indexes --database=national

执行该命令后,索引会被部署到"national"数据库,而非默认数据库。

方法二:通过firebase.json配置默认目标数据库

如果需要默认将索引部署到"national"数据库,可以修改项目根目录下的firebase.json文件,添加Firestore数据库的指定配置:

{
  // 保留其他原有配置
  "firestore": {
    "database": "national"
  }
}

配置完成后,执行常规部署命令firebase deploy --only firestore:indexes,索引就会自动部署到"national"数据库。

内容的提问来源于stack exchange,提问作者RyanY

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 07:32:05