0

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

2
  • 2
    Possible duplicate of Firebase querying data Commented Mar 19, 2018 at 3:47
  • @NileshRathod which didn't work for my scenario. The below answer is the correct one. Thanks. Commented Mar 19, 2018 at 3:57

1 Answer 1

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().

Sign up to request clarification or add additional context in comments.

Comments

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.