我目前正在使用新的Firestore作为后端/数据库对Android应用程序进行概念验证。我需要按其ID提取一堆文件(它们都在同一个集合中)
现在,我遍历id列表,并将它们逐个获取,并将它们存储在列表中,这反过来又会更新应用程序中的RecycleView。这似乎是一项艰巨的工作,并且效果不佳。
从Firestore提取文档列表而不必循环所有id并使它们一个接一个的正确方法是什么?
现在我的代码看起来像这样
for (id in ids) {
FirebaseFirestore.getInstance().collection("test_collection").whereEqualTo(FieldPath.documentId(), id)
.get()
.addOnCompleteListener {
if (it.isSuccessful) {
val res = it.result.map { it.toObject(Test::class.java) }.firstOrNull()
if (res != null) {
testList.add(res)
notifyDataSetChanged()
}
} else {
Log.w(TAG, "Error getting documents.", it.exception)
}
}
}
最佳答案
Firestore当前不支持按ID查询。
根据AngularFirebase的说法,这是 future 发展的路线图,但是它不是官方的:
Keep in mind, Firestore is still in beta. Firebase engineers hinted at some really cool features on the roadmap (geo queries, query by array of ids) - I’ll be sure to keep you posted :)
关于firebase - 在Firestore中按ID提取多个文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49347277/