我正在检查名为 attending
的 boolean 字段是否存在,但我不确定该怎么做。
是否有诸如 .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");
}
}
}
});
最佳答案
您可以执行以下操作:
if(task.isSuccessful()){
for(QueryDocumentSnapshot document: task.getResult()){
if (document.exists()) {
if(document.getBoolean("attending") != null){
Log.d(TAG, "attending field exists");
}
}
}
}
来自docs :
public boolean exists ()
Returns true if the document existed in this snapshot.
关于java - 如何检查该字段是否存在于 firestore 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58180481/