Firebase Firestore - 使用受限安全规则迭代集合
Firebase Firestore - Iterate collection with restricted security rules
在 Firestore 中,我定义了这样的规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, list: if request.data.visibility == "public";
}
}
}
然后我想获取所有 public 个文档,所以我使用 AngularFire 订阅了该集合:
this.docs = db.collection('documents', ref => ref.where("visibility", "==", 'public')).snapshotChanges();
但这抛出:
Missing or insufficient permissions.
这是应该发生的吗?是否可以迭代具有受限文档的集合?我不是子集合的忠实粉丝,但这是实现此目标的唯一方法吗?
已解决,我缺少列表规则,而且我也没有添加文档集合。最终规则是这样的:
service cloud.firestore {
match /databases/{database}/documents {
match /documents/{document=**} {
allow read, list: if resource.data.visibility == "public"
}
}
}
在 Firestore 中,我定义了这样的规则:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, list: if request.data.visibility == "public";
}
}
}
然后我想获取所有 public 个文档,所以我使用 AngularFire 订阅了该集合:
this.docs = db.collection('documents', ref => ref.where("visibility", "==", 'public')).snapshotChanges();
但这抛出:
Missing or insufficient permissions.
这是应该发生的吗?是否可以迭代具有受限文档的集合?我不是子集合的忠实粉丝,但这是实现此目标的唯一方法吗?
已解决,我缺少列表规则,而且我也没有添加文档集合。最终规则是这样的:
service cloud.firestore {
match /databases/{database}/documents {
match /documents/{document=**} {
allow read, list: if resource.data.visibility == "public"
}
}
}