firestore规则函数get()和存在()未返回所需结果。我在做什么错?
这是我正在使用的Firestore数据库的准排骨结构。 名称均为小写
编辑
- :
- 所有 居民子集合
1的工作目的是 2不是
match /databases/{database}/documents {
match /hostels/{hostelId} {
allow read, write: if request.auth.uid != null;
match /rooms/{roomId} {
allow read, write: if exists(/databases/$(database)/documents/
hostels/$(hostelId)/admins/$(request.auth.uid));
allow read: if exists(/databases/$(database)/documents/
hostels/$(hostelId)/rooms/$(roomId)/residents/$(request.auth.uid));
}
}
}
在阅读室作为居民时,我会遇到错误,
Null value error. for 'list' @ L49
我也通过阅读居民文档的布尔领域而尝试使用Get(),没有运气。
我在做什么?是否存在限制()和get()路径参数深度?任何帮助都将是
我用来查询居民的代码,
let q = collection(this.hostelCollection,
this.residentSnap.get('hostel_id'), "rooms")
let docs = await getDocs(q);
居民文档具有Hostel_ID字段,其中包含Hostel ID
This is barebone structure of the Firestore database that I am using.
edit: all names are in small letters
The rules I want is
- admins of a hostel can read all the rooms of the hostel
- residents of a room can only view the room if the room has the residents id in its
residents subcollection
1 is working as intented
2 is not
match /databases/{database}/documents {
match /hostels/{hostelId} {
allow read, write: if request.auth.uid != null;
match /rooms/{roomId} {
allow read, write: if exists(/databases/$(database)/documents/
hostels/$(hostelId)/admins/$(request.auth.uid));
allow read: if exists(/databases/$(database)/documents/
hostels/$(hostelId)/rooms/$(roomId)/residents/$(request.auth.uid));
}
}
}
while reading rooms as resident i get error
Null value error. for 'list' @ L49
I also tried with get() by reading a boolean field of resident document and no luck.
what am i doing worng? Is there a limit to exists() and get() path argument depth? Any help would be much appriciated
the code i use to query rooms by resident is
let q = collection(this.hostelCollection,
this.residentSnap.get('hostel_id'), "rooms")
let docs = await getDocs(q);
resident document has hostel_id field containing hostel id
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加单个
允许阅读
语句并重构规则,如下所示:Try adding a single
allow read
statement and refactoring the rules as shown below: