Recently, I inquired about how to filter products based on their child property. You can find the original question here: Filter products based on the sub child in Firebase.
To summarize, my data structure is as follows:
products/
product1
/author: 12345
/title: "Awesome"
/category: "catA"
/description: "more awesome"
product2
/author: 67890
/title: "Other"
/category: "catB"
/description: "otherawesome"
product3
/author: 12345
/title: "Billy"
/category: "catB"
/description: "otherawesome"
To filter out all products with author 12345
, you can use the following query:
ref.child("products").orderByChild('author').equalTo(12345)...
But what if you need to use multiple AND or OR statements?
For example, how do you filter for:
all products with author
12345
AND categorycatA
(resulting inproduct1
)all products with author
12345
OR author 67890 (resulting inproduct1
andproduct3
)
I attempted the following query for the first scenario:
ref.child("products").orderByChild('author').equalTo(12345).orderByChild('category').equalTo('catA')...
Unfortunately, this resulted in an error (
You can't combine multiple orderBy calls
).
For more information, you can refer to: https://www.firebase.com/docs/web/guide/retrieving-data.html#section-queries