2

I use firebase in my android app, but i'm facing problems. For example. I have this 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"

I want to select males living in England. How do I rearrange my data to get there knowing we can not do two orderby

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Possible duplicate of [Query based on multiple where clauses in firebase](http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase) – Frank van Puffelen Dec 02 '15 at 15:09
  • Firebase queries can only order on one property (or priority or key). But in cases such as this, you can combine the values into a single property. See http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase/26701282#26701282 – Frank van Puffelen Dec 02 '15 at 15:11

1 Answers1

2

First - take a look at this answer , for similar question: Query based on multiple where clauses in firebase

Anyway, you can add country level to your data structure, so your data can look something like:

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

Then you can easily query for males living in England.

Another option that described in the link on the top , is to add a key that combine both country & gender, and then query this property.

Community
  • 1
  • 1
giladk
  • 176
  • 6