我正在尝试为我的应用设置安全规则。
我有一个看起来像这样的收藏集:
Scores
|
|
|
|
|___ AutoID______________history
| |___value: 22 |__20190506
| |___userID: "abc" |___dateString:20190506
|___ AutoID |___value:22
|___value: 45
|___userID: "def"
我认为这样做没关系:
match /scores/{docID=**} {
allow read: if userIsLoggedIn();
allow create, update: if request.resource.data.userID == request.auth.uid;
allow delete: if resource.data.userID == request.auth.uid;
}
分数可以由用户达到,但不能达到Collection
“历史记录”。我认为问题出在resource.data.userID
。
Collection
“历史记录”无法访问resource.data.userID
。我想从父文档访问resource.data.userID
。
可以这样做吗?
如果您要使用的文档字段不在该规则检查的具有读写访问权限的文档中,则您必须使用以下方法get()
另一个文档(即使它位于父路径中)完整路径,以便您可以在规则中使用其字段值。在get()
的文档中了解更多信息。
如果您在规则中不使用全局通配符,而是通过名称来调用子集合,则可能会更容易,因此您可以使用单个通配符值更轻松地构建父文档的路径。像这样的东西:
accessing other documents
这不是确切的规则,但我希望您能在这里看到我在做什么,以便制定自己的规则。