How to list all recent where members 0th index equal to "5"?
Asked
Modified
7 years, 8 months ago
Viewed
839 times
Part
of Mobile Development and Google Cloud Collectives
2
-
2Possible duplicate of Firebase querying dataAskNilesh– AskNilesh2018-03-19 03:47:16 +00:00Commented Mar 19, 2018 at 3:47
-
@NileshRathod which didn't work for my scenario. The below answer is the correct one. Thanks.Chathura Wijesinghe– Chathura Wijesinghe2018-03-19 03:57:49 +00:00Commented Mar 19, 2018 at 3:57
Add a comment
|
1 Answer
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().
