I am creating a simple chat application and I need a way to retrieve all of a user's messages. I have the following data structure:
Messages{ -LmPsSIlmS8c6ph5UoOi { formattedTime: "05:43 PM" message: "Hey there" receiverId: "GvaD3JOgp5Ro6TWZCa3I7RvK7682" senderId: "3BPkGaQq62gnQCbO5UHFIw4XVps2" }
I would like to make a query that selects all the messeges where senderId = user.getUid() OR receiverId = user.getUid()
I've seen posts all around the internet that firebase doesn't do this but there has to be a way around it because I doubt you can ever build a large application without OR queries.
I've tried:
myRef.child("Messages").orderByChild("senderId")
.startAt(user.getId()).endAt(user.getId()).orderByChild("receiverId")
.startAt(user.getId()).endAt(user.getId())
.addValueEventListener(
new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
This hasn't worked, though I've searched far and wide for a simple solution without getting any answers. Kindly help