JamesG
JamesG6mo ago

Filtering a Firestore call with OR condition

Hi, I'm trying to retrieve all documents with one or both of two booleans set to "true". I've tried all sorts of variants on the below but no joy: { "condition": "OR", "rules": [ { "field": "behaviourist", "operator": "==", "value": true }, { "field": "trainer", "operator": "==", "value": true } ] } Thanks in advance!
Solution:
Hi @JamesG, Add the Filters in array: [{field:"user1",value:"test",operator:"=="}, {field:"user",value:"true",operator:"=="}] to set multiple filter in Firestore collection query....
Jump to solution
3 Replies
Solution
Gaurav Chadha
Gaurav Chadha6mo ago
Hi @JamesG, Add the Filters in array: [{field:"user1",value:"test",operator:"=="}, {field:"user",value:"true",operator:"=="}] to set multiple filter in Firestore collection query.
JamesG
JamesG6mo ago
Thanks @Gaurav Chadha, but that applies multiple filters together so is an AND condition. I need OR, if that's possible.
Gaurav Chadha
Gaurav Chadha6mo ago
For OR, you can modify the filter logic to have:
where('state', '==', 'CA'),
or(
where('capital', '==', true),
where('population', '>=', 1000000)
)
where('state', '==', 'CA'),
or(
where('capital', '==', true),
where('population', '>=', 1000000)
)
Supported filter query operators - https://cloud.google.com/firestore/docs/query-data/queries#query_operators.