Konstantin Konopko
Konstantin Konopko

Reputation: 5420

Realtime Database query with two generated fields

I have the following DB structure, then I need get data filtered by "date" field. How do I do that?

root {
  places {
    $placeUid {
      $bookingUid {
        date: String
        name: String
      }
    }
  }
}

My query looks like that, and it doesn't work:

refPlaces = Firebase.database.getReference("places")
refPlaces.orderByChild("date").equalTo("14.10.2020").addValueEventListener(…)

Upvotes: 0

Views: 50

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599121

Firebase queries work on a flat list of child nodes, where the value you order/filter on is in a fixed path under each direct child node. Since you have two dynamic levels under places, you won't be able to query for it.

The solution is to create a flat list of bookings for this use-case, with each booking then having the place Uid as a property in each booking.

For more on this, see:

Upvotes: 1

Related Questions