如何检查该字段在Firestore中是否存在? [英] How to check if the field exists in firestore?
本文介绍了如何检查该字段在Firestore中是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在检查称为 attending
的布尔字段是否存在,但是我不确定如何做到这一点.
I am checking whether the Boolean field called attending
exists, however I am not sure how to do that.
是否有诸如 .child().exists()
之类的功能或我可以使用的类似功能?
Is there a function such as .child().exists()
or something similar that I could use?
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");
}
}
}
});
推荐答案
您现在正在做的是正确的-您必须阅读文档并检查快照以查看该字段是否存在.没有比这更短的方法了.
What you're doing now is correct - you have to read the document and examine the snapshot to see if the field exists. There is no shorter way to do this.
这篇关于如何检查该字段在Firestore中是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文