Reputation: 145
I want to avoid returning documents from Firestore that I do not need. I have a collection of documents with the following properties:
membership {array}
0 {map}
contactGroupId: "1da9a73f89f8ca4c"
contactGroupResourceName: "contactGroup/1da9a73f89f8ca4c"
1 {map}
contactGroupId: "1da9a73f89f8ca4c"
contactGroupResourceName: "contactGroup/1da9a73f89f8ca4c"
I want to create a compound query that only returns documents if the contactGroupId is equal to 1da9a73f89f8ca4c. Something like ref.where(membership.{key}.contactGroupId, "==", "1da9a73f89f8ca4c")
. Is this possible?
Upvotes: 0
Views: 25
Reputation: 317750
It's not possible to filter documents using the contents of a map field inside an array. You will need to restructure your data if you want to perform this query. You have two options.
contactGroupId
values into their own array field, and use an array-contains query to find them.contactGroupId
value as the name of a map key that you can use in a query, like where(
membership.1da9a73f89f8ca4c.present, '==', true)
. Your membership field would be structure like this:membership (map)
- 1da9a73f89f8ca4c
- present (boolean)
- contactGroupResourceName = "contactGroup/1da9a73f89f8ca4c"
Upvotes: 1