【发布时间】:2023-03-22 12:40:01
【问题描述】:
大家好。
我正在为一家医院编写一个具有这种数据库结构的颤振应用程序。
我在获取会话数据时遇到问题,正是以下文档。
使用以下方法获取治疗师的lastSession,使用他的治疗师UID作为过滤字段。
Future<Session> getLastSession() async {
Query query;
query = Firestore.instance
.collection("sessions")
.where("therapistUID",
isEqualTo: this.uid)
.orderBy("date", descending: true)
.limit(1); //this.uid = auth uid of current therapist.
try {
QuerySnapshot querySnapshot = await query.getDocuments(); //exception thrown here
if (querySnapshot.documents.isEmpty) {
throw Exception("Empty query");
} else {
lastSession = Session.fromDocument(querySnapshot.documents[0]);
return lastSession;
}
} catch (e) {
throw Exception("cannot get data from database");
}}
遵循以下规则
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /patients/{document=**} {
allow read,write,list: if checkPatientAccess(resource.data);
}
match /therapists/{document=**} {
allow read,write,list: if checkOwnership();
}
match /sessions/{document=**} {
allow read, write,list: if checkPatientAccess(get(/databases/$(database)/documents/patients/$(resource.data.patientUID)).data);
}
match /devices/{document=**} {
allow read, write,list: if false;
}
match /clinics/{document=**} {
allow read, write,list: if false;
}}}
function checkOwnership(){
return resource.id == request.auth.uid;
}
function checkPatientAccess(patient){
return request.auth.uid in patient.therapistUIDs;
}
代码抛出此异常
有谁知道它为什么拒绝查询?请记住,查询只是一个文档,并且数据库中只有一个文档可以适合这些过滤器。使用具有相同参数的 testlab 是可行的。
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore firebase-security