如何使用火力通过查询订单做 [英] How to do order by query using firebase
问题描述
我用我的Android应用火力点。我需要帮助找到一个问题我的麻烦。我想做这样的恳求:我用的是oderbyChild(DATE)通过执行此操作奥德从最近日期到最远我的数据
。 MyApplication.backend.child(URL)的.orderByChild(值)。addValueEventListener(新ValueEventListener(){
}
现在我想这全选,其中活性值完成和秩序的主题我的日期值。我有写:
<$p$p><$c$c>MyApplication.backend.child(urls).orderByChild(\"task\").equalTo(\"done\").addValueEventListener(new ValueEventListener(){}
我的问题是,这是不可能做到在同一个火力点查询2两orderByChild。我怎样才能解决这个问题?请需要帮助。
假设你的数据看起来像这样
活动
-JKjasjiji
日期:20151129
is_done:假的
-Ykkjaso23
日期:20151128
is_done:真
-Jkaisjiij
日期:20151127
is_done:假的
有几种方法去这个问题。
1)中的所有活动,其中is_done查询:true,则在code中的结果进行排序。这可能取决于数据集大小是非常低效的。在code排序100万会很糟糕。
2)存储在另一个节点的完成活动
活动
-JKjasjiji
日期:20151129
-Jkaisjiij
日期:20151127done_activities
-Ykkjaso23
日期:20151128
3)存放在一个格式的数据,将启用和类型的查询
活动
-JKjasjiji
done_and_date:false_20151129
-Ykkjaso23
done_and_date:true_20151128
-Jkaisjiij
done_and_date:false_20151127
然后用户.startAt和.endAt ...
ref.orderByKey()。startAt(true_20151128)。ENDAT(true_20151129)
会放弃返回在两个指定日期之间进行的所有活动。
I'm using firebase on my android app. I need help to find an issue to my trouble. I want to do a request like this: I was using the oderbyChild("date") to oder my data from the nearest date to the farest by doing this.
MyApplication.backend.child(urls).orderByChild("value").addValueEventListener(new ValueEventListener() {
}
now i want to this select all where the activity value is done and order theme by my date value. i have write this :
MyApplication.backend.child(urls).orderByChild("task").equalTo("done").addValueEventListener(new ValueEventListener(){
}
My problem is that it's not possible to do 2 two orderByChild on the same fireBase query. How can i fix this ? please need help.
Assuming your data looks like this
activities
-JKjasjiji
date: 20151129
is_done: false
-Ykkjaso23
date: 20151128
is_done: true
-Jkaisjiij
date: 20151127
is_done: false
There are a few ways to go about this.
1) query for all activities where is_done: true then sort the results in code. This could be very inefficient depending on data set size. Sorting 1 Million in code would be bad.
2) Store the done activities in another node
activities
-JKjasjiji
date: 20151129
-Jkaisjiij
date: 20151127
done_activities
-Ykkjaso23
date: 20151128
3) Store the data in a format that will enable an 'and' type query
activities
-JKjasjiji
done_and_date: false_20151129
-Ykkjaso23
done_and_date: true_20151128
-Jkaisjiij
done_and_date: false_20151127
Then user .startAt and .endAt...
ref.orderByKey().startAt("true_20151128").endAt("true_20151129")
Would give return all activities that are done between the two specified dates.
这篇关于如何使用火力通过查询订单做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!