Reputation: 936
I built a data structure in firestore like that:
How to order all documents in cities by the salary of doctor document in Job sub-collections?
Thanks for your help!
Upvotes: 6
Views: 2847
Reputation: 3139
The documentation says you can't:
Limitations: You can't easily delete subcollections, or perform compound queries across subcollections.
What I would do is create another collection called SalariesByCity or something, that contains:
Then you could first query this collection filtering by the job and ordering by the salary (you will need to create an index for that), and then for each line you can query the City collection by ID to get the city details.
You could also include the city name in this SalariesByCity collection so you wouldn't even need to perform another query. But then you need to always update this collection whenever you update the city. Transactions might be helpful for that.
So your collection could be something like this:
Upvotes: 5