运行此查询时
self.db.collection("strokedata").whereField("uid", isEqualTo: coachid!).addSnapshotListener { (querySnapshot, err) in
有了这些规则,
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
match /strokedata/{document} {
allow write: if isSignedIn() && document == request.auth.uid;
allow read: if document == request.auth.uid || request.auth.uid == resource.data.uid;
}
match /users/{document} {
allow create: if request.auth.uid != null;
allow read: if request.auth != null;
allow write: if document == request.auth.uid;
}
}
}
resource.data.uid中的uid文本代码变为绿色,并且查询有效。
但是,当我运行此查询时
self.db.collection("strokedata").whereField("coachuid", isEqualTo: coachid!).addSnapshotListener { (querySnapshot, err) in
使用这些规则,它将不起作用,在这种情况下,指导代码不会在规则中变为绿色。
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
match /strokedata/{document} {
allow write: if isSignedIn() && document == request.auth.uid;
allow read: if document == request.auth.uid || request.auth.uid == resource.data.coachuid;
}
match /users/{document} {
allow create: if request.auth.uid != null;
allow read: if request.auth != null;
allow write: if document == request.auth.uid;
}
}
}
我有一些可行的方法,但是我很好奇为什么coachuid查询不会变成绿色并且规则每次都失败。