0

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(…)
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Konstantin Konopko
  • 5,229
  • 4
  • 36
  • 62

1 Answers1

1

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:

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