【发布时间】:2021-03-29 21:11:54
【问题描述】:
我正在尝试创建一个集合,如果它在 firestore 中不存在。
我的代码如下
val docRef = fbase.collection("cities").document("LA")
docRef.get().addOnSuccessListener {
document ->
if(document!= null){
Toast.makeText(this, "Already exists", Toast.LENGTH_LONG).show()
}
else{
FireBaseRepository
Toast.makeText(this, "Does not exists", Toast.LENGTH_LONG).show()
}
}
“FireBaseRepository”只是一个带有初始化集合的类。我的代码总是通过 if 条件,因为 FirebaseFirestore.java 类确保集合不能为空。我已经看过推荐的链接https://firebase.google.com/docs/firestore/query-data/get-data?hl=en。
@NonNull
public CollectionReference collection(@NonNull String collectionPath) {
checkNotNull(collectionPath, "Provided collection path must not be null.");
ensureClientConfigured();
return new CollectionReference(ResourcePath.fromString(collectionPath), this);
}
【问题讨论】:
标签: android kotlin google-cloud-firestore