How to list all recent
where members
0
th index equal to "5"
?
Asked
Active
Viewed 822 times
0

ReyAnthonyRenacia
- 17,219
- 5
- 37
- 56

Chathura Wijesinghe
- 3,310
- 3
- 25
- 41
-
2Possible duplicate of [Firebase querying data](https://stackoverflow.com/questions/39024702/firebase-querying-data) – AskNilesh Mar 19 '18 at 03:47
-
@NileshRathod which didn't work for my scenario. The below answer is the correct one. Thanks. – Chathura Wijesinghe Mar 19 '18 at 03:57
1 Answers
1
Something like this should work:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("recent");
Query query = ref.orderByChild("members/0").equalTo("5");
query.addValueListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
System.out.println(childSnapshot.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException());
}
});
The trick here is that you specify the relative path to the property that you want to order/filter on in orderByChild()
.

Frank van Puffelen
- 565,676
- 79
- 828
- 807