Firebase query orderByChild

我是研究僧i 提交于 2021-01-29 11:19:31

问题


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.


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!