问题
I want to perform a query to a firebase database.
My database is as follows:
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.
回答1:
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.
来源:https://stackoverflow.com/questions/54372135/firebase-query-orderbychild