I really can't find how to do it, how do I get in my RecyclerView all the values of a certain department. First things first, is it even possible? This is how my Firestore database loos like this, "blue_bottle" and "tops_national" is part of a document:
I want to populate my RecyclerView with all products, both out of "blue_bottle" and "tops_national" with the same department. So I need a DocumentReference which I believe is right:
private val promoOnedb = FirebaseFirestore.getInstance()
private val promoOneRef: DocumentReference = promoOnedb.collection("tops")
.document("promotions")
But how do I query that DocumentReference now to show all products, in both collections to show all products of the same department? Please.
CodePudding user response:
The only way in Firestore to read across multiple collections is with a collection group query, which reads from all collections with a specific name.
o with a single collection group query you can read from all blue_bottle
collections or all tops_national
collections. There is no feature in Firestore however to read from all blue_bottle
collections and all tops_national
collections with a single operation. You will need at least two (collection group) queries for that, and thus merge the results from those in your application code.
If you want to read all products with a single operation, they will need to be stored in collections of the same name, like products
. Only then can you use a single collection group query to read them all in one go.