0

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

klapinski
  • 151
  • 1
  • 8

1 Answers1

0

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
Jay
  • 34,438
  • 18
  • 52
  • 81
  • thank you for your help but i just tried couple solutions and i think a better one would be quering keys id7-11 on server side and then do filtering by category on client side, i'm fetching items 10 at once so it goes pretty nice, besides i need category text without subscript – klapinski Mar 01 '17 at 19:22
  • @kam.voick You can keep a another child node for the actual text. What I posted is a typical design pattern in Firebase to query by two parameters. Glad you had another solution. – Jay Mar 01 '17 at 22:15