Considering this data structure:
{
"users":{
"user-1":{
"groups":{
"group-key-1":true,
"group-key-3":true
}
}
},
"groups":{
"group-key-1":{
"name":"My group 1"
},
"group-key-2":{
"name":"My group 2"
},
"group-key-3":{
"name":"My group 3"
},
"group-key-4":{
"name":"My group 4"
},
}
}
I could get the groups of a particular user with:
firebase.database().ref('users/user-1/groups').on(...)
Which would give me this object:
{
"group-key-1":true,
"group-key-3":true
}
So now I want to retrieve the info for those groups.
My initial instinct would be to loop those keys and do this:
var data = snapshot.val()
var keys = Object.keys(data)
for (var i = 0; i < keys.length; i++) {
firebase.database().ref('groups/' + keys[i]).on(...)
}
Is this the appropriate way to call multiple keys on the same endpoint in Firebase?
Does Firebase provide a better way to solve this problem?