I have read a good article on how to structure a firebase database for a chat app and I ended app in this structure:
{
"users":{
"autoIdUser1":{
"username":"john",
"full_name":"John Vincent",
"groups":{
"autoIdGroup1":true,
"autoIdGroup2":true
}
},
"autoIdUser2": ...,
"autoIdUser3": ...
}
"groups": {
"autoIdGroup1"{
"group_name":"Administrators",
"group_description":"Users who can do anything!",
"members":{
"autoIdUser1":true,
"autoIdUser2":true
}
},
"autoIdGroup2"{
"group_name":"Moderators",
"group_description":"Users who can only moderate!",
"members":{
"autoIdUser1":true
}
}
}
}
Now I have to retrive from my db all rooms where a member is in
What I tried to do is to do a query to check if in each group is there a specific user id under members but I can't figure how...
I also thanked about another way creating another structure in db like this:
"membersInGroups":{
"autoIdGroup1":{
"autoIdMember1":true,
"autoIdMember3":true
}
"autoIdGroup2":{
"autoIdMember1":true
}
}
and then create a query to retrive all groups id where a user is in and use those to query again all info for each group. The style of query is the same of that I have to make with old structure but is simplier
Which method is the best?
If I add the second structure, can I remove "members" child node??
Can I see an example of the query for the existing structure?