我在 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/