I have a collection and an array of names and the collection can be queried directly by id
I want to access a unique subcollection depending on a name and I want to return the sub collection after
Query is structured as such
firestore
.collection
.where("name", '==', inputName)
.collection('subCollection')
.get()
This does not seem to work, is there an alternative way
Firestore queries can only inspect data in the documents that they return. There is no way to return documents from the subcollection, and filter on a field from the parent documents.
The common solution is to add the name to each document in the subcollections too (say as a field called parentName), and then perform a collection group query across all collections named subCollection:
firestore
.collectionGroup('subCollection')
.where("parentName", '==', inputName)
.get()