【发布时间】:2017-11-04 13:06:44
【问题描述】:
我正在尝试使用 Cloud Forestore 来保存用户数据。我设置的规则是这样的:
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userID} {
allow read: if request.auth.uid == userID;
match /{lists} {
allow write: if request.auth.uid == userID;
}
}
match /users/test {
allow read, write: if true;
}
}
}
我试图完成的是用户应该能够阅读 {userID} 中的所有内容,包括子集合和子文档。此外,用户应该能够写入 {lists} 集合以及每个子集合和子文档。
我这样访问 Cloud Firestore:
db.collection("users").document(mAuth.getUid()).collection("lists").document(String.valueOf(document.getDocId()))
.set(cloudListInfo)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
error = 0;
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
error = -3;
globalVars.logException(TAG, "docInfo:ExportToCloud FAILURE", e);
}
});
}
我得到的错误是这样的:
FAILURE:Exception.string:com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions.
我可以访问“测试”集合及其值。
我使用允许写入/读取所有内容的规则为我的用户创建了一条记录,就像“测试”匹配中的规则一样。这是在我努力使用更详细的规则保护数据之前完成的。
我不明白为什么这不起作用。这很可能是微不足道的事情,但我几乎盲目地试图找到原因......
【问题讨论】:
标签: android google-cloud-firestore