如何从Firestore导出安全性和索引规则?

uks*_*ksz 3 firebase google-cloud-firestore firebase-security-rules

我在Firestore开发数据库上设置了多个不同的索引.现在,我想将它们导出到firestore.indexes.json这样,以便设置prod环境的过程更容易.有没有办法使用Firebase CLI导出这些索引?这同样适用于安全规则,虽然我知道我可以复制粘贴它们.

mes*_*eeb 69

在您的 Firebase 项目文件夹中,在终端中执行以下命令:

firebase firestore:indexes > firestore.indexes.json
Run Code Online (Sandbox Code Playgroud)

它会保存一个名为firestore.indexes.json的文件和您的索引。

然后,您可以将该文件上传到其他 Firebase 项目。

  • 那么如何将特定的 json 文件“部署”到不同的数据库呢? (3认同)

fyl*_*epo 20

这是可能的!

从firebase firestore:indexes您的firebase项目文件夹中的CLI运行.

如果您已经设置了索引并通过CLI登录到Firebase,您将获得格式化的JSON输出供您复制.

例:

{
  "indexes": [
    {
      "collectionId": "teslaData",
      "fields": [
        {
          "fieldPath": "Model",
          "mode": "ASCENDING"
        },
        {
          "fieldPath": "Price",
          "mode": "ASCENDING"
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

4.2.1如果有帮助,我正在使用Firebase CLI ,祝你好运:)

  • 像这样使用它:firebase firestore:indexes > firestore.indexes.json (6认同)
  • 这对我使用 firebase-tools (firebase-cli) 8.7.0 有用。 (2认同)

xin*_*ose 11

这就是我的项目文件的布局方式

myProjectFolder

  • .firebaserc
  • firebase.json
  • firestore.indexes.json
  • functions

  • firebase use myApp-dev然后运行命令firebase firestore:indexes > firestore.indexes.json将当前开发项目的索引导出到文件中

    • myApp-dev是myApp-prod“项目 ID”。要在 Firebase 中找到它,请单击“项目概述”旁边的齿轮 --> 项目设置 --> 常规选项卡(您应该在下面看到它)

在文件中firebase.json确保它指向导出的索引firestore.indexes.json:

{
  "functions": [
    {
      "source": "functions",
      "codebase": "default",
      "ignore": [
        "node_modules",
        ".git",
        "firebase-debug.log",
        "firebase-debug.*.log"
      ],
      "predeploy": [
        "npm --prefix \"$RESOURCE_DIR\" run lint",
        "npm --prefix \"$RESOURCE_DIR\" run build"
      ]
    }
  ],
  "firestore": {
    "indexes": "firestore.indexes.json"
  }
}
Run Code Online (Sandbox Code Playgroud)
  • 运行命令firebase use myApp-prod并firebase deploy --only firestore:indexes