2

I want to retrive all data in my firebase database which genre has "Gospel"

Here's my database:

enter image description here

DatabaseReference infoRef = FirebaseDatabase.getInstance().geReference().child("info");

infoRef.orderByChild("genre").orderByValue().equalTo("Gospel").addValueEventListener( new ValueEventListener(){
    @Override
    public void onDataChange(DataSnapshot dataSnapshot){
     log.i("data", dataSnapshot.toString());
    }

    @Override
    public void onCancelled(DatabaseError databaseError){

    }
});

I need other query because multiple orderBy is invalid.

Thanks...

Eleazer Toluan
  • 233
  • 4
  • 14
  • You can only order by/filter on one property. See http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase. But once you filter on the genre, you can re-order the data client-side. – Frank van Puffelen Nov 09 '16 at 07:08
  • One more solution is that, given the fact an album belongs to a single genre, you could structure the data as genre : "Gospel" and use a orderByChild("genre").equalTo("Gospel") to get the parent node – Veeresh Charantimath Nov 09 '16 at 07:12

1 Answers1

2

Multiple orderBy are not allowed in Firebase

Try this

infoRef.orderByChild("genre").equalTo("Gospel").addValueEventListener( new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
 log.i("data", dataSnapshot.toString());
}

@Override
public void onCancelled(DatabaseError databaseError){

}
});
Veeresh Charantimath
  • 4,641
  • 5
  • 27
  • 36