0

How to list all recent where members 0th index equal to "5"?

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
Chathura Wijesinghe
  • 3,310
  • 3
  • 25
  • 41

1 Answers1

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