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

标签 firebase google-cloud-firestore firebase-security

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

最佳答案

这是可能的!
从 CLI 运行 firebase firestore:indexes在您的 firebase 项目文件夹中。
如果您已经设置了索引并通过 CLI 登录到 Firebase,您将获得一个格式化的 JSON 输出供您复制。
例子:

{
  "indexes": [
    {
      "collectionId": "teslaData",
      "fields": [
        {
          "fieldPath": "Model",
          "mode": "ASCENDING"
        },
        {
          "fieldPath": "Price",
          "mode": "ASCENDING"
        }
      ]
    }
  ]
}
导出的索引可以使用 firebase deploy --only firestore:indexes 重新导入.检查以下文档摘录。
https://firebase.google.com/docs/firestore/query-data/indexing

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如果有帮助,祝你好运:)
编辑:它仍然在工作 9.6.0 .

关于firebase - 如何从 Firestore 导出安全和索引规则?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52778542/

相关文章:

javascript - Firebase+Chrome 应用程序(无扩展程序)

javascript - 运行集合组查询以查看我的 firebase 子集合中的字段是 true 还是 false

ios - 如何创建新收藏集?

firebase - 是否可以将 Firebase Auth 与外部 SQL 数据库集成?

javascript - 如何使用 AngularFire 实现基于角色的访问控制

web - 如何根据设备平台为 firestore 指定安全规则?

firebase - 已删除的用户有权访问 Firebase Firestore

ios - 检测Google用户之前是否登录过

javascript - query.startAt 数据库规则权限被拒绝

firebase - 我可以循环浏览 Firestore 事务中的文档吗?