![](/img/trans.png)
[英]How do I check if a document exists within a collection (Firebase REACT)?
[英]Android Firebase, How to check if a subcollection exists within a document
有没有办法检查 android 的文档中是否存在子集合? 我只需要将文档添加到新的子集合中一次。
您可以使用FirebaseFirestore
API 的 Documents getter 方法,它就像:
public boolean isSubCollectionDocAvailable(subCollectionDocName: String) {
AtomicBoolean isAvailable = new AtomicBoolean(false);
FirebaseFirestore.getInstance()
.collection("ParentCollection")
.document("ParentDoc")
.collection("SubCollection")
.document(subCollectionDocName)
.limit(1)
.get()
.addOnSuccessListener(result -> {
isAvailable.set(result.exists());
});
return isAvailable.get();
}
这是数据库层次结构: https://i.stack.imgur.com/BpQ7j.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.