1

I have the structure in the image below and I want to get the whole data from the node "aaa1234" querying by "id_Usuario". How can I do that query?

This is my structure

I tried:

DatabaseReference root = database.getReference().child("Eventos").child("participantes");
Query query = root.orderByChild("id_Usuario").equalTo(2);

Just to be more clear, the "aaa1234" is a custom key, so it will be different in the next node.

2
  • You're storing the user ID as a number, so shouldn't have quotes around the value in equalTo. So: .equalTo(2) Commented May 12, 2017 at 4:30
  • Thx for that, I missed it, but still not working. Commented May 12, 2017 at 4:33

1 Answer 1

2

I see two mistakes.

The first one is a typo, which I already marked in my comment. You're storing the user ID as a number, so shouldn't have quotes around the value in equalTo. So: .equalTo(2)

The second mistake is in the way you try to query:

DatabaseReference root = database.getReference().child("Eventos").child("participantes");

This will create a reference to the non-existing child Eventos/participantes. What you want to do instead is query Eventos, but then against property participantes/id_Usuario. So

DatabaseReference root = database.getReference().child("Eventos");
Query query = root.orderByChild("participantes/id_Usuario").equalTo(2);
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.