【问题标题】:Need a query out of multiple collections from Firestore需要从 Firestore 的多个集合中查询
【发布时间】:2021-12-10 07:47:54
【问题描述】:

实在找不到怎么办,怎么在我的RecyclerView中获取某个部门的所有值。 首先,这有可能吗? 这就是我的 Firestore 数据库的松散方式,“blue_bottle”和“tops_national”是文档的一部分:

我想用同一部门的“blue_bottle”和“tops_national”中的所有产品填充我的 RecyclerView。 所以我需要一个我认为正确的 DocumentReference:

private val promoOnedb = FirebaseFirestore.getInstance()
private val promoOneRef: DocumentReference = promoOnedb.collection("tops")
    .document("promotions")

但是我现在如何查询 DocumentReference 以显示所有产品,在两个集合中显示同一部门的所有产品?请。

【问题讨论】:

标签: android firebase kotlin google-cloud-firestore android-recyclerview


【解决方案1】:

在 Firestore 中读取多个集合的唯一方法是使用 collection group query,它从具有特定名称的所有集合中读取。

o 使用单个集合组查询,您可以从所有 blue_bottle 集合或所有 tops_national 集合中读取。 Firestore 中没有功能可以通过单个操作读取所有blue_bottle 集合所有tops_national 集合。为此,您将需要至少两个(集合组)查询,从而合并应用程序代码中的结果。

如果您想通过一次操作读取所有产品,则需要将它们存储在同名的集合中,例如products。只有这样,您才能使用单个集合组查询一次性读取所有内容。

【讨论】:

    猜你喜欢
    • 2020-07-24
    • 1970-01-01
    • 2019-01-09
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 2023-01-19
    相关资源
    最近更新 更多