4

I am trying to implement a query or something similar where I can retrieve data from Firebase where I can get cars that have at least one matching tag with the currently displayed car.

Here is my Object and the way it is structured on Firebase

"cars": {
   "carID1": {
   "name": "car1",
   "id": "carID1",
   "tags": { 
       "0": "racing",
       "1": "sport" 
       },
   },
}

For example I have a car with tags: 'sport' and 'automate' and would like to display all the other cars that have either 'sport' or 'automate' tag.

What would be the best way to implement a query of this sorts ?

anho
  • 1,705
  • 2
  • 20
  • 38
  • 2
    https://firebase.googleblog.com/2013/10/queries-part-1-common-sql-queries.html#byemail – muescha Jan 28 '17 at 16:32
  • so would the .startAt / .endAt approach be the best ? – anho Jan 28 '17 at 16:34
  • no - the best is when you make an index with your tags where you put for each tag the carIds if you ask: that is the best. (see blog) – muescha Jan 28 '17 at 16:51
  • 1
    There are a few things wrong with this approach. I wrote this answer a while ago: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value (mostly because I'd forgotten about Kato's classic blog post on the topic). – Frank van Puffelen Jan 28 '17 at 17:59

0 Answers0