我在查询文档对它们具有不同权限的集合时遇到了问题。
无论如何都要对集合执行查询以防止在我无法读取的文档上获得权限被拒绝。如果我一次查询一个,我就能实现这一点。我需要查询集合以返回多个文档,其中我可能没有权限。我可以保留一个特定用户有权查询的文档ID列表,但是我找不到任何关于指定文档数组的文档。
收集:
Library > { libraryID } > {
Users:{ uid, uid, uid },
title: 'Title of library'
}
规则:
match /Library/{libraryID} {
allow read: if get(/databases/$(database)/documents/Library/$(libraryID)).data.Users[(request.auth.uid)] == true;
}
如果用户ID在数据中,则权限有限。
这很好用:
this.afs.collection<Library('Library').doc({libraryID}); // Everything works great
但是我需要集合中的多个项目,所以当我尝试下面的示例时,如果失败,因为我没有对集合中所有文档的权限:
this.afs.collection<Library('Library'); //PERMISSION DENIED
我希望我可以使用查询来修复此问题,但因为它正在查看文档,它也会失败:
this.afs.collection<Library('Library',ref => ref.where('Users/'+this._uid, '==', 'true')); // PERMISSION DENIED
所以我希望我可以指定我可以访问的文档(这是我需要的)并将它们返回到集合中
this.afs.collection<Library('Library').doc([{libraryID},{libraryID2},{libraryID3}])
如果有人知道实现这一目标的解决方案,或者实现此目的的结构重构,那将是一个巨大的帮助。
答案 0 :(得分:0)
尝试此规则
ImageButton
其中说,如果match /Library/{libraryID} {
allow read: if exists(/databases/$(database)/documents/Library/$(libraryID)/Users/$(request.auth.uid));
}
节点中存在当前用户ID,则允许读取。