firefly1337 firefly1337 - 1 month ago 8
Android Question

Read data from different directories using Firebase for Android

/users:
- user1
- name: user1name
- /contacts
- user2
- user3
.....
- user2
- name: user2name
....


This is my current firebase database. When user1 is logged in I check which contacts he has and get their UIDs. Now that I have their UIDs I'm trying to read the names of his contacts. How can I get the names for each of his contacts? Do I have to read the entire /users directory or can I use a query that retrieves only the data that I want. (In this case: the name of user2 and user3)

Answer

You'd do a nested read. So retrieve /users/$uid/contacts, then loop over the keys in there and for each key load /users/$key.