如何从 Firestore 导出安全和索引规则? [英] How to export security and index rules from Firestore?

查看:19
本文介绍了如何从 Firestore 导出安全和索引规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've set up multiple different indexes on my Firestore development database. Now, I would like to export them into the firestore.indexes.json so that the process of setting up prod environment would be easier. Is there a way to export those indexes using Firebase CLI? The same applies to security rules, although I know that I can copy paste them.

推荐答案

有可能!

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

Run from CLI firebase firestore:indexes inside your firebase project folder.

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

Providing you have indexes already setup and logged into Firebase via the CLI too, you'll get a formatted JSON output for you to copy.

示例:

{
  "indexes": [
    {
      "collectionId": "teslaData",
      "fields": [
        {
          "fieldPath": "Model",
          "mode": "ASCENDING"
        },
        {
          "fieldPath": "Price",
          "mode": "ASCENDING"
        }
      ]
    }
  ]
}

导出的索引可以使用 firebase deploy --only firestore:indexes 重新导入.检查以下文档摘录.

Exported indexes can be re imported using firebase deploy --only firestore:indexes. Check following doc extract.

https://firebase.google.com/docs/firestore/query-数据/索引

您还可以使用 Firebase CLI 部署索引.要开始,请运行firebase init firestore 在您的项目目录中.在设置过程中,Firebase CLI 生成一个带有默认索引的 JSON 文件正确的格式.编辑文件以添加更多索引并使用firebase 部署命令.如果只想部署索引,添加--only firestore:indexes 标志.如果您对索引进行编辑使用 Firebase 控制台,请确保您还更新了本地索引文件.

You can also deploy indexes with the Firebase CLI. To get started, run firebase init firestore in your project directory. During setup, the Firebase CLI generates a JSON file with the default indexes in the correct format. Edit the file to add more indexes and deploy it with the firebase deploy command. If you only want to deploy indexes, add the --only firestore:indexes flag. If you make edits to the indexes using the Firebase console, make sure you also update your local indexes file.

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

I'm using Firebase CLI 4.2.1 if that helps, good luck :)

它从 9.6.0 开始仍然有效.

It's still working as of 9.6.0.

这篇关于如何从 Firestore 导出安全和索引规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆