firebase - 用于在文档中收集的 Firestore 安全规则
问题描述
我正在尝试保护我在 Firestore 中的数据。我已经阅读了文档并设法为我的数据库的大部分内容安排了规则,但我遇到了一个特定的情况:
数据的结构是这样的:
集合(“连接”).document(Uid1).collection(Uid2).().()
我想允许 Uid1 和 Uid2 访问整个树。此功能的规则是什么?
解决方案
您应该使用递归通配符语法,{name=**}
如文档中所述。
service cloud.firestore { match /databases/{database}/documents { // Matches any document in the cities collection as well as any document in a subcollection. match /cities/{document=**} { allow read, write: if <condition>; } } }
当使用递归通配符语法时,通配符变量将包含整个匹配的路径段,即使文档位于深度嵌套的子集合中。例如,上面列出的规则将匹配位于 的文档
/cities/SF/landmarks/coit_tower
,并且文档变量的值将是SF/landmarks/coit_tower
。
请注意,您需要使用规则版本 2。
推荐阅读
- angular - 应用Filter后如何获取Array的长度
- node.js - 将自定义“TLD”添加到电子网络视图的最佳方法是什么
- python - 在浏览器中收听文本
- python - Flask REST: TypeError: get() got an unexpected keyword argument
- r - R中的复杂排序算法
- node.js - node js搜索系统正则表达式
- javascript - 从服务器中的公共 API 获取数据并发送到客户端
- swift - How to know when PDF document is downloaded in PDFKit?
- batch-file - 遍历子文件夹并从 zip 文件夹中删除某些文件名
- docker - Docker cli 使用较旧的日志记录?