我的Firestore中有一个示例结构:文档用户和文档香水。用户可以有FavouritePerfumes收集和香水文档的Ids。如何获取特定用户的fvourite香水属性,如: name和brad?



发布于 2021-03-13 00:12:48
如果您试图直接从favoritePerfumes子集合获取数据,而您已经拥有了userId,那么您实际上可以将它链接到其父对象的documentReference,并使用get()来完成此操作。
这里有一个你可以应用到你的案例中的例子:
var documentReference = db.collection("users").document(userId)
documentReference.collection("favoritePerfumes")
.get()
.addOnSuccessListener { result ->
for (document in result) {
var name = document.get("name")
var brand = document.get("brand")
Log.d(TAG, "The name is ${name} and the brand is ${brand}")
}
}
.addOnFailureListener { exception ->
Log.d(TAG, "Error getting documents:", exception)
}https://stackoverflow.com/questions/66581790
复制相似问题