Receiving items with query and keys range

36 views Asked by At

here's simple structure:

$countryCode
 -autoid13
  -category: vehicles
 -autoid12
  -category: sport
 -autoid11
  -category: food
 -autoid10
  -category: sport
 -autoid9
  -category: vehicles
 -autoid8
  -category: food
 -autoid7
  -category: sport
 -autoid6
  -category: sport

my question is how can i fetch only items with category: sport between items with id7-id11 ? /autoid keys are managed by firebase

1

There are 1 answers

2
Jay On

Here's how to do it

countryCode
 -autoid13
  -category: vehicles_13
 -autoid12
  -category: sport_12
 -autoid11
  -category: food_11
 -autoid10
  -category: sport_10
 -autoid9
  -category: vehicles_09
 -autoid8
  -category: food_08
 -autoid7
  -category: sport_07
 -autoid6
  -category: sport_06

and pseudo-code

   ref.orderBy("category")
      .queryStartingAtValue("sport_07")
      .queryEndingAtValue("sport_11")

will return

 -autoid7
  -category: sport_07
 -autoid10
  -category: sport_10