I want to do double filtering related to Firestore. I have a city selection button and the second one is a ListView that selects the products category.
My category filtering works well, but I don't know how to add more city filtering for it.
](https://i.stack.imgur.com/68SIS.png)
I tried to write something like this
stocks.where('city', arrayContains: 'Chicago').where('tags', arrayContains: 'All');
But this is wrong. I will be grateful for any answer.
CodePudding user response:
The following line of code:
stocks.where('city', arrayContains: 'Chicago').where('tags', arrayContains: 'All');
Will not work, because there is a query limitation that says:
You can use at most one array-contains clause per query. You can't combine array-contains with array-contains-any.
So you can use only one arrayContains
in a query.
To solve this, you should consider using maps, and not arrays, a case in which the following database schema will do the trick:
Firestore-root
|
--- stocks
|
--- $stockId
|
--- cities
| |
| --- "Chicago": true
|
--- tags
|
--- "All": true
Then a query like the one below will work perfectly fine:
stocks.whereEqualTo("cities.Chicago", true).whereEqualTo("tags.All", true);