0

Given this database structure in Firebase Realtime database,

enter image description here

I would like to get list of quotes based on a specific category.

If user selects "Motivation" then all quotes under that category should be returned. For e.g. in the above structure, quotes ID: 1,2,5 are under category "Motivation" so if a user selects motivation (from a dropdown in UI) then only the quotes ID: 1,2,5 should be returned in the snapshot.

How to form a firebase query such that only 1,2,5 are returned in the snapshot.

Thanks

appu
  • 471
  • 1
  • 8
  • 26

1 Answers1

0

There is no single query that can do this in Firebase, since the Realtime Database doesn't support any form of server-side joins.

So you will need to:

  1. Attach a listener to the category under /category.
  2. Loop over the child nodes in the snapshot you get.
  3. Attach an individual listener for each key under /quotes

This approach is not nearly as slow as many developers initially think, since Firebase pipelines the requests where possible. See Speed up fetching posts for my social network app by using query instead of observing a single event repeatedly

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Can u pls give a quick example, particularly expressing this statement `Attach an individual listener for each key under /quotes`. thanks – appu Apr 23 '19 at 16:46