1

I have a project returning data from IOT devices in different rooms. The data is set up as:

<firebase_url>
  |-<room_id>
  |  |-<report_id>
  |  |  |-<data>
  |  |
  |  |-<report_id>
  |     |-<data>
  |
  |-<room_id>

I want to be able to query based on info in the <data> but it keeps telling me I need an index. The problem is that the room id's aren't hard coded. They're set from the devices. Is there a way to do this without needing to add an index for every new room added?

CaseyB
  • 24,780
  • 14
  • 77
  • 112
  • In addition to Frank van Puffelen's answer, you can also consider using Cloud Firestore and use a [collection group query](https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query). – Alex Mamo Mar 06 '23 at 07:23

1 Answers1

0

Firebase Realtime Database can order/filter nodes at a path on a value that exists on a fixed, known path under each direct child node.

So in your data structure that means that you can query a specific room for data in the individual reports, but you can't query across all reports of all rooms. If you want that, consider either unnesting the data into a flat list, or creating an additional flat list of the nodes to allow this query.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807