Android Firestore错误限制_至_优先,can';无法读取firestore值
我正在尝试从firestore获取数据,虽然它以前工作过,但现在停止工作,并且我一直收到此错误- [Firestore]:侦听查询失败(目标=查询(用户/默认/关键/主订单由名称);限制类型=首先限制到 我的数据库规则定义如下-Android Firestore错误限制_至_优先,can';无法读取firestore值,android,firebase,google-cloud-firestore,firebase-security,Android,Firebase,Google Cloud Firestore,Firebase Security,我正在尝试从firestore获取数据,虽然它以前工作过,但现在停止工作,并且我一直收到此错误- [Firestore]:侦听查询失败(目标=查询(用户/默认/关键/主订单由名称);限制类型=首先限制到
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
/*-----tile menus----------*/
match /users/defaultmenuItems/{document=**} {
allow read: if isOwner(userId);
allow write: if false;
}
match /users/{userId}/{document=**} {
allow read,write,update: if isOwner(userId);
}
function isOwner(userId) {
return request.auth.uid == userId;
}
}
}
users/defaultmenuItems/critical/home
在Android中执行查询的代码
public void readMenu(final String collection, final String path, final DataRead dataStatus) {
firebaseFirestore.collection(collection)
.document(userId + path)
.get()
.addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot documentSnapshot = task.getResult();
if (documentSnapshot.exists()) {
dataStatus.DataIsRead(documentSnapshot);
} else {
getDeafaultItems(collection, path);
}
} else {
Log.d(TAG, "Sorry ....");
}
}
});
}
private void getDeafaultItems(final String collection, final String path) {
Log.d("MY_PATH",collection + "/defaultmenuItems"+path);
firebaseFirestore.collection(collection)
.document("defaultmenuItems" + path)
.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists()) {
copyFromDefaults(collection, documentSnapshot, path);
}
}
});
}
default查询有一个错误,我用上面的正确路径修复了这个错误。但问题仍然存在。这条规则:
match /users/defaultmenuItems/{document=**} {
allow read: if isOwner(userId);
allow write: if false;
}
指的是一个变量
userId
,它在这里根本不存在。该名称没有通配符,因此userId
没有值。不清楚您希望该值从何而来,但您需要重写此规则(或重新构造数据)以更准确地表达您的安全要求。如果看不到执行查询的代码,我们将无能为力。该查询显然被某些规则拒绝,但无法判断是哪一个或如何解决它。请用更多的细节编辑问题,并解释什么没有按您期望的方式工作。@DougStevenson我已经添加了代码。你能查一下吗?信息还是不够。我们看不到您在查询中使用的变量的值,因此我们不知道您正在尝试使用哪个集合或文档。硬编码所有的值,这样我们就可以看到发生了什么。任何人都应该能够获取您的代码并复制该问题。@BL∧CK,您确定请求.auth.uid
具有值默认值?尝试更改isoowner
以始终返回true
。“行得通吗?”道格·史蒂文森我已经更新了我的问题。我的查询中有一个错误,但问题仍然存在。是的,我已经知道了。但无论如何,非常感谢你的帮助:)注意安全:)