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

查看:67
本文介绍了如何从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初始化为Firestore.在设置过程中, Firebase CLI会生成一个JSON文件,其中包含默认索引 正确的格式.编辑文件以添加更多索引并使用 firebase deploy命令.如果只想部署索引,请添加 --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 :)

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

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