Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java firestore,其中equalto始终返回true_Java_Android_Google Cloud Firestore - Fatal编程技术网

Java firestore,其中equalto始终返回true

Java firestore,其中equalto始终返回true,java,android,google-cloud-firestore,Java,Android,Google Cloud Firestore,我想在firestore数据库中设置一个侦听器 我想听听一个名为isConfirmClicked的值,如果它等于1,我想知道它 我使用以下方法: db.collection( "Users" ).document( NotMyID ).collection( "MyChats" ).whereEqualTo( "isConfirmClicked" , 1 ).addSnapshotListener( new EventListener&

我想在firestore数据库中设置一个侦听器

我想听听一个名为
isConfirmClicked
的值,如果它等于1,我想知道它

我使用以下方法:

db.collection( "Users" ).document( NotMyID ).collection( "MyChats" ).whereEqualTo( "isConfirmClicked" , 1 ).addSnapshotListener( new EventListener<QuerySnapshot>() {
    @Override
    public void onEvent(@Nullable QuerySnapshot value,
                        @Nullable FirebaseFirestoreException e) {
        if (e != null) {
            return;
        }

        DO SOMETHING HERE
        
    }
} );
db.collection(“Users”).document(NotMyID).collection(“MyChats”).whereEqualTo(“isConfirmClicked”,1).addSnapshotListener(new EventListener()){
@凌驾
public void onEvent(@Nullable QuerySnapshot value,
@可为空的FireBaseFireStore异常(e){
如果(e!=null){
返回;
}
在这里做点什么
}
} );
出于某种原因,它总是进入
此处执行操作
,即使确定isConfirmClicked等于0


有什么原因吗?

只要查询结果已知,即使没有匹配的文档,也会调用您提供的侦听器。如果您想知道查询是否有匹配的文档,则需要使用其方法检查提供的文档

或者,您可以检查
querySnapshot.size()
>0

@Override
public void onEvent(@Nullable QuerySnapshot querySnapshot,
                    @Nullable FirebaseFirestoreException e) {
    if (e != null) {
        return;
    }

    if (!querySnapshot.isEmpty()) {
        // here, there is at least one document that matches the query
    }        
}