3

I have following database

-KYTfJZQbg0RVzHeecIS
     createdAt: 1481204648530
     message: "rgd"
     read: false
     reciever: "583d15cf45f3330807364c55"
     sender: "58490e9945f33364ac6cd7b1"
     updateAt: 1481204648654

Now I want to filter the result for "READ"==FALSE AND "SENDER"==58490e9945f33364ac6cd7b1

how can I achieve this?

Any help would be appreciated Thanks

EDIT :-

I am using this in android as

Query query = reference.orderByChild("read").equalTo(false)
                .orderByChild("sender").equalTo(datum.getEmployer().getEmployerId());

it gave java.lang.IllegalArgumentException: You can't combine multiple orderBy calls!

Akshay Sood
  • 6,366
  • 10
  • 36
  • 59

2 Answers2

6

Multiple orderbychild() queries is not supported by firebase .

Now I want to filter the result for "READ"==FALSE AND "SENDER"==58490e9945f33364ac6cd7b1

Make a new key in your data i.e. READ_SENDER and combine data for both and use query like this -

-KYTfJZQbg0RVzHeecIS
     createdAt: 1481204648530
     message: "rgd"
     read: false
     reciever: "583d15cf45f3330807364c55"
     sender: "58490e9945f33364ac6cd7b1"
     read_sender : "false_58490e9945f33364ac6cd7b1"
     updateAt: 1481204648654


Query query = reference.orderByChild("read_sender").equalTo("false_"+datum.getEmployer().getEmployerId());
HarshitG
  • 2,677
  • 3
  • 16
  • 13
  • or just add method `public String getReadSender(){return read+"_"+sender;}` to Item.class. But the method should be WITHOUT annotation `@Exclude` – NickUnuchek Jan 22 '19 at 13:45
4

Unfortunately this isn't straightforward using Firebase.....there's good example of doing something very similar in following video by Firebase guys (about 9 mins in) https://www.youtube.com/watch?v=sKFLI5FOOHs&list=PLl-K7zZEsYLlP-k-RKFa7RyNPa9_wCH2s&index=4

John O'Reilly
  • 10,000
  • 4
  • 41
  • 63
  • We can not use multiple orderby like this Query query = reference.orderByChild("read").equalTo(false) .orderByChild("sender").equalTo(datum.getEmployer().getEmployerId()); else it will throw exception :- java.lang.IllegalArgumentException: You can't combine multiple orderBy calls! – Akshay Sood Dec 08 '16 at 14:23
  • yes, that's exactly what's discussed in the section of that video I mentioned above. – John O'Reilly Dec 08 '16 at 14:54
  • @JohnO'Reilly how to achive result? – Aditya Vyas-Lakhan May 02 '17 at 09:04
  • Not working because in this video show same think:- Query query = reference.orderByChild("read").equalTo(false) .orderByChild("sender").equalTo(datum.getEmployer().getEmployerId()); – Appnweb31 Dec 13 '18 at 09:30