在Flutter中使用集合组查询时出现上述错误。
由于缺少集合组查询的权限,我收到此错误,即使我拥有子集合的以下权限
forums
match /forums/{forumid}/posts/{post} {
// Only authenticated users can read
allow read: if request.auth != null;
// Only the post author can write
allow write: if request.auth != null && request.auth.uid == resource.data.author;
}
s 我发现 this 其中指出:
在安全规则中,您必须通过为集合组编写规则来明确允许集合组查询:
- 确保
是规则集的第一行。集合组查询需要安全规则版本 2 的新递归通配符
rules_version = '2';
行为。{name=**}
- 使用
为您的收集组编写规则。
match /{path=**}/[COLLECTION_ID]/{doc}
因此像下面这样更新权限是可行的
match /{path=**}/posts/{post} {
allow read: if request.auth != null;
}
match /forums/{forumid}/posts/{postid} {
// Only a post's author can write to a post
allow write: if request.auth != null && request.auth.uid == resource.data.author;
}