真的很难找到这个问题,因为它有时会发生,而且很幸运我在打开logcat时发现了这个错误。
问题是:当我打开活动并请求数据时,我看不到加载的数据并收到logcat警告
[Firestore]:侦听查询(执行myField == someValue按名称的练习)失败:ay {code = PERMISSION_DENIED,description =缺少或 权限不足。,cause = null}
第一个想法可能是-错误的索引,错误的规则等。但这是在我多数时候“有时”说的时候发生的。
我注意到,当应用程序第一次读取数据或将Internet连接状态更改回在线状态时,就会发生这种情况。
所以看起来像个错误,不是吗?可能您已经遇到了这个问题。你能帮我吗?
这是有问题的简单代码块:
CollectionReference collection = db.collection("myCollection");
collection.whereEqualTo("myField","someValue")
.addSnapshotListener(this, new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot snapshot,
@Nullable FirebaseFirestoreException e) {
//magic
}
}
规则:
match /someitems/{someitem}{
allow read: if request.auth.uid != null &&
(resource.data.enable == true || isAdmin());
allow write: if isAdmin()
}
索引(已更新,请参见下面的评论):
someitems:
title: asc
kit: asc
language: asc
enable: asc
PS:我使用最新的Firebase依赖项
谢谢!