Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.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中是否存在该字段?_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Java 如何检查firestore中是否存在该字段?

Java 如何检查firestore中是否存在该字段?,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我正在检查名为attenting的布尔字段是否存在,但是我不确定如何执行该操作 是否有像.child().exists()这样的函数或类似的函数可以使用 firebaseFirestore.collection("Events") .document(ID) .collection("Users") .get() .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

我正在检查名为
attenting
的布尔字段是否存在,但是我不确定如何执行该操作

是否有像
.child().exists()
这样的函数或类似的函数可以使用

firebaseFirestore.collection("Events")
    .document(ID)
    .collection("Users")
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if(task.isSuccessful()) {
                for(QueryDocumentSnapshot document: task.getResult()){
                    attending = document.getBoolean("attending");
                }
            }
        }
    });
firebaseFirestore.collection(“事件”)
.文件(ID)
.收集(“用户”)
.get()
.addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
对于(QueryDocumentSnapshot文档:task.getResult()){
出席=document.getBoolean(“出席”);
}
}
}
});

您现在所做的是正确的-您必须阅读文档并检查快照以查看该字段是否存在。没有比这更快捷的方法了。

您可以执行以下操作:

  if(task.isSuccessful()){
    for(QueryDocumentSnapshot document: task.getResult()){
       if (document.exists()) {
          if(document.getBoolean("attending") != null){
             Log.d(TAG, "attending field exists");
          }
        }
      }
  }
从:

public boolean存在()

返回 如果此快照中存在文档,则为true