I'm just getting started with Firebase Database and am having some troubles wrapping my head around efficiently querying data. My current database structure is similar to the Firebase documentation for recommended data structures, where we see this example:
// An index to track Ada's memberships
{
"users": {
"alovelace": {
"name": "Ada Lovelace",
// Index Ada's groups in her profile
"groups": {
// the value here doesn't matter, just that the key exists
"techpioneers": true,
"womentechmakers": true
}
},
...
},
"groups": {
"techpioneers": {
"name": "Historical Tech Pioneers",
"members": {
"alovelace": true,
"ghopper": true,
"eclarke": true
}
},
...
}
}
The problem I'm having is that I'm not sure how to efficiently retrieve all of the group names for a specific user. I can retrieve all of the group IDs for a user easily:
usersRef.child("alovelace").child("groups").observeSingleEvent(of: .value, with: { (snapshot) in
// code to store group IDs
})
But now the only way I can think to get all the group names is to make a for loop through the IDs, then make a .observeSingleEvent call for each one to get the name. But what if I have a very large set of groups for the user? Ideally I'd prefer not to make so many database calls and just do it in one call. Is that possible with this data structure?