需要从 Firestore 的多个集合中查询
Need a query out of multiple collections from Firestore
我实在是找不到怎么办,怎么才能在我的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 以显示所有产品,在两个集合中以显示同一部门的所有产品?请。
Firestore 中读取多个集合的唯一方法是使用 collection group query,它从具有特定名称的所有集合中读取。
o 使用单个集合组查询,您可以从所有 blue_bottle
个集合或所有 tops_national
个集合中读取。但是,Firestore 中没有任何功能可以通过一次操作从所有 blue_bottle
个集合 和 所有 tops_national
个集合中读取。您至少需要两个(集合组)查询,然后合并应用程序代码中的结果。
如果您想通过一次操作读取所有产品,则需要将它们存储在同名集合中,例如products
。只有这样,您才能使用单个集合组查询来一次读取它们。
我实在是找不到怎么办,怎么才能在我的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 以显示所有产品,在两个集合中以显示同一部门的所有产品?请。
Firestore 中读取多个集合的唯一方法是使用 collection group query,它从具有特定名称的所有集合中读取。
o 使用单个集合组查询,您可以从所有 blue_bottle
个集合或所有 tops_national
个集合中读取。但是,Firestore 中没有任何功能可以通过一次操作从所有 blue_bottle
个集合 和 所有 tops_national
个集合中读取。您至少需要两个(集合组)查询,然后合并应用程序代码中的结果。
如果您想通过一次操作读取所有产品,则需要将它们存储在同名集合中,例如products
。只有这样,您才能使用单个集合组查询来一次读取它们。