Firebase查询orderByChild [英] Firebase query orderByChild

查看:48
本文介绍了Firebase查询orderByChild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查询Firebase数据库.

I want to perform a query to a firebase database.

我的数据库如下:

我想通过orderByChild值已付费"查询"paymentStatus".

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");

谢谢.

推荐答案

Firebase数据库查询功能在子节点列表上,而不是树上.数据库将在您查询的位置下获取每个直接子节点,然后在您指定的属性上进行排序/过滤.

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.

Visits 的子节点下没有属性 paymentStatus ,这是因为 paymentStatus 的层次更深.这意味着在当前数据模型中,无法执行所需的查询.如果您想按 paymentStatus 过滤访问次数,则需要确保您拥有一个统一的访问列表.

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.

另请参阅我对 Firebase Query Double Nested 的回答.

这篇关于Firebase查询orderByChild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆