在firebase上做查询

时间:2015-12-02 14:59:40

标签: android request firebase firebase-realtime-database

我在我的Android应用程序中使用firebase,但我遇到了问题。例如。我有这个entrie

persons
    -kskhdhksdhh
        name:"Vladimir"
        age:"25"
        sexe:"M"
        country:"Russia"
    -jhgsdhghsgs
        name:"Victoria"
        age:"20"
        sexe:"F"
        country:"England"
    -zejhbshevzh
        name:"John"
        age:"44"
        sexe:"M"
        country:"England"

我想选择住在英格兰的男性。我如何重新安排我的数据,以便知道我们不能做两个命令

1 个答案:

答案 0 :(得分:2)

首先 - 看看这个答案,对于类似的问题: Query based on multiple where clauses in firebase

无论如何,您可以在数据结构中添加国家/地区级别,因此您的数据可能类似于:

persons
    -Russia
       -kskhdhksdhh
           name:"Vladimir"
           age:"25"
           sexe:"M"
     -England
       -jhgsdhghsgs
           name:"Victoria"
           age:"20"
           sexe:"F"
       -zejhbshevzh
           name:"John"
           age:"44"
           sexe:"M"

然后,您可以轻松查询居住在英格兰的男性。

在顶部的链接中描述的另一个选项是添加一个结合了country& amp;性别,然后查询此属性。