【发布时间】:2019-10-01 05:05:45
【问题描述】:
我已经设置了一个简单的 Firestore 数据库来存储数据并处理规则/权限。我可以访问一个名为“workplace”的集合中的数据,但我无法读取名为“employee”的新集合中的数据
我已尝试将规则更改为:
allow read: if true;
我可以读取数据
我在应用中的查询:
db.collection("employee")
.whereEqualTo("workplaceId", w.getId())
.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
for (QueryDocumentSnapshot doc : queryDocumentSnapshots) {
Employee e = doc.toObject(Employee.class);
e.setId(doc.getId());
Log.d(TAG, "staff: " + e.getFirstName());
}
}
});
我在 Firestore 中的规则:
service cloud.firestore {
match /databases/{database}/documents {
match /workplace/{workplaceID} {
allow read: if resource.data.ownerId == request.auth.uid;
allow write: if request.auth.uid != null;
}
match /employee/{employeeID} {
allow read: if resource.data.workplaceId == request.resource.data.workplaceId;
allow write: if request.auth.uid != null;
}
}
}
我希望能够获取“员工”集合中的所有文档,其中它们的“workplaceId”等于我传入的数据。
请参阅下面我的数据库结构图像的链接:
【问题讨论】:
标签: java android google-cloud-firestore firebase-security