Query nested data from Firebase Real-time database Android

后端 未结 1 1300
半阙折子戏
半阙折子戏 2020-12-21 22:14

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?

1条回答
  •  轮回少年
    2020-12-21 23:07

    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);
    

    0 讨论(0)
提交回复
热议问题