1

enter image description here

I am trying this code:

Query query = FirebaseDatabase.getInstance().getReference("Current Location")
         .orderByChild("email_id").equalTo("pratiksiddhapura11@gmail.com")
         .orderByChild("date").equalTo("2019/11/18");

but this is not worked on me and give an error like this:-

  • You can't combine multiple orderBy calls!

I want user data where email_id="pratiksiddhapura11@gmail.com" and date = "2019/11/18"

Any other solution?

For Android(JAVA)

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Yes it's true. In firebase query **You can't combine multiple orderBy calls**. You can filter date after getting data in client side – Md. Asaduzzaman Dec 30 '19 at 08:55
  • In this case you can do all filtering on the server by adding a property that combines the values of `email_id` and `date`, like `"email_id-date": "pratiksiddhapura11@gmail.com-2019/11/18"`. This way you can filter on both values, by simply checking a single property. My answer to the linked question show more on how to do that. – Frank van Puffelen Dec 30 '19 at 15:53

1 Answers1

3

Firebase doesn't support multiple orderBy calls. You can apply one filter in server side and another one in client side.

Check below implementation: Here I have used email_id in server side and date in client side to filter data. Hope this will help you.

Query query = FirebaseDatabase.getInstance().getReference("Current Location").orderByChild("email_id").equalTo("pratiksiddhapura11@gmail.com");
query.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        for(DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
            YourModel yourModel = childSnapshot.getValue(YourModel.class);

            if(yourModel.getDate().equalsIgnoreCase("2019/11/18")) {
                // Here is your desired location
            }
        }
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {

    }
});
Md. Asaduzzaman
  • 14,963
  • 2
  • 34
  • 46