My data is denormalized and uses a reverse index like suggested by the firebase team. Something similar to:
{
"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
}
},
...
}
}
Now I want to load all of Ada's groups. I can easily get a list of the group IDs that she belongs to since it's part of her user object.
Is there a way for me to query all of Ada's specific groups by ID at once? Or do I need to create a ValueEventListener
per group ID and request each group separately?
On the security side - let's assume that every group is only readable by its members, so I can't query all groups and sort them after the fact.
I guess you could do something like:
var ref = new Firebase("<..>/groups");
ref.orderByChild("members/alovelace").equalTo(true)
.once('value').then(function(dataSnapshot) {
// handle read data
})
(Untested, but according to this Deep-Queries are now supported)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With