Filter products on multiple child properties in Firebase

前端 未结 1 901
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 13:17

I recently asked how to filter products based on their child property (see: Filter products based on the sub child in Firebase).

As a recap my structure looks as follows

相关标签:
1条回答
  • 2021-01-21 14:19

    From what I've read here, the way to do this is to perform the first query (preferably the one that will return the fewest results), then filter by the other field in javascript. Another way to do this, and I'd recommend this if you are performing this query often, is create a compound index for the query like; the answer by Frank van Puffelen in the link above gives an example of this.

    products/
         product1
            /author: 12345
            /title: "Awesome"
            /category: "catA"
            /description: "more awesome"
            /author_category: "12345_catA"
         product2
            /author: 67890
            /title: "Other"
            /category: "catB"
            /description: "otherawesome"
            /author_category: "67890_catB"
         product3
            /author: 12345
            /title: "Billy"
            /category: "catB"
            /description: "otherawesome"
            /author_category: "12345_catB"
    

    As for the 'OR', I've looked for quite a while and found nothing to help you. I'd suggest two separate queries.

    0 讨论(0)
提交回复
热议问题