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!

2 Answers 2

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());
Sign up to request clarification or add additional context in comments.

1 Comment

or just add method public String getReadSender(){return read+"_"+sender;} to Item.class. But the method should be WITHOUT annotation @Exclude
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

4 Comments

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!
yes, that's exactly what's discussed in the section of that video I mentioned above.
@JohnO'Reilly how to achive result?
Not working because in this video show same think:- Query query = reference.orderByChild("read").equalTo(false) .orderByChild("sender").equalTo(datum.getEmployer().getEmployerId());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.