0

I have the following hierarchy:

enter image description here

I am using this table to generate real-time search updates for my searchBar and I want to make the following things:

  1. If a user searches for "dsa", show him the results for "dsa". (Done)

    ref.queryOrderedByKey()
            .queryStarting(atValue: queryLower)
            .queryEnding(atValue: queryLower + "\u{f8ff}")
    ...
    
  2. User will be able to select from which table the results to be shown so I embedded the table names as a value in order to search for them. I want, when a user selected the button Search in Sports Center, with a value of "dsa" to show him only the "dsa" results that have a value of "sports center".

To make this work I was thinking:

ref.queryOrderedByKey()
            .queryStarting(atValue: queryLower)
            .queryEnding(atValue: queryLower + "\u{f8ff}")
            .queryOrderedByValue()
            .queryEqual(toValue: tableName)
...

The problem is that it crashed on .queryOrderedByValue. Seems like you can't chain query ordering or I don't know how.

How can I make this work or is it a better architecture I can employ to solve my problem?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Teodor Ciuraru
  • 3,417
  • 1
  • 32
  • 39
  • 1
    You can only `orderBy` one type of element you can't `orderByKey` and `orderByValue` with Firebase. You'll need to filter your results on the front-end in order to run additional queries. – sketchthat Feb 25 '18 at 22:23
  • As sketchthat says, a Firebase Database query can only contain a single `queryOrderedBy...` clause. It may be possible to combine the two values that you're trying to filter on into a single property, e.g. `"value_key": "sports center_dsadasda"` and then filter on that. For more on this and other options, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Feb 25 '18 at 22:45

0 Answers0