Reputation: 55
I am trying to retrieve data from two tables in a database. I understand that if I want to read from a child I do this:
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
So what do I do for two children?
My data looks like this:
Upvotes: 1
Views: 3174
Reputation: 355
I'll assume 2 possibilities for your question.
First: you want to retrieve a child of a child
appName{
"users" : {
"Bob" : {
"age" : 20
}
}
In this case to access a specific user you should do:
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child("Bob");
But if you mean that you have different child like: users and questions
appName{
"users" : {
"Bob" : {
"age" : 20
}
}
"questions" : {
"who am I?"
}
}
Then, you should make a reference to each one of them:
usersRef = FirebaseDatabase.getInstance().getReference().child("Users");
questionsRef = FirebaseDatabase.getInstance().getReference().child("questions");
Upvotes: 1