1

I have the following data structure:

items:
  id1 - dynamically set, unknown
    id2 - dynamically set, known
      item: data

I want to get all data inside id2.

Using firebase.database().ref('items').orderByChild('item').equalTo('data') I get null but at the same time it's no problem to access all data inside id1 though. Apparently using this method it's impossible to access data with 2 and more levels of depth.

Firebase declares they support up to 32 levels of nesting. So there should be some methods for advanced searching data anyways.

How can one access an object with known property and known value while searching at 2 or more levels of depth with arbitrary keys?

droidBomb
  • 850
  • 5
  • 8
Igniter
  • 857
  • 9
  • 24

1 Answers1

1

Unfortunately firebase realtime database gives you the ability to filter children only one level deep. If you have the flexibility to reach the specific id1(which you declared unknown), you can filter with orderByChild and equalTo method for item by going down the hierarchy. Alternatively you can filter manually client side or change your data structure if you have the chance.

From the firebase reference:

Filter by key or value

You can use startAt(), endAt(), and equalTo() to choose arbitrary starting, ending, and equivalence points for queries. This can be useful for paginating data or finding items with children that have a specific value.

https://firebase.google.com/docs/database/web/lists-of-data

Mert Ozdal
  • 82
  • 5
  • Thanks! That's weird and something nature-specific I guess. Maybe you know is it true for their new Cloud Firestore too or not? – Igniter Sep 28 '18 at 12:11
  • Hi Igniter, I don’t have any experience with the Firestore so I don’t want to mislead you;) – Mert Ozdal Sep 28 '18 at 13:49