Firebase query orderByChild

I want to perform a query to a firebase database.

My database is as follows:

database

I want to query "paymentStatus" by orderByChild value "paid".

How will my query code look? The below code not reading.

Query query = FirebaseDatabase.getInstance().getReference().child("Visits")
       .orderByChild("paymentStatus").equalTo("Paid");

Thank you in advance.

Upvotes: 0

Views: 305

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599946

Firebase database queries function on a list of child nodes, not on a tree. The database takes each direct child node under the location you query and then sorts/filters on the property you indicate.

There is no property paymentStatus directly under the child nodes of Visits, because the paymentStatus is one level deeper. That means that in your current data model, the query you want is not possible. If you want to filter visits by paymentStatus you will need to ensure that you have a single, flat list of visits.

Also see my answer to Firebase Query Double Nested.

Upvotes: 1

Related Questions