user3519221
user3519221

Reputation: 119

Firebase retrieve all where child has specific object

I need some help with a Firebase query.

How can I retrieve all users where in the child "groups" a specific group exists?

Every user object in de database looks like this:

"067f010c-5580-450a-84ba-6e94880886c2": {
    "goal": 
    {
        "distance": "10",
        "time": "20"
    },
    "groups": 
    {
        "-KH0O99wyxT61xVfjnH5": 
        {
            "group_id": "-KH0O99wyxT61xVfjnH5",
            "name": "Test"
        },
        "-KH0OFDI9jjReE75y7Dj": 
        {
            "group_id": "-KH0OFDI9jjReE75y7Dj",
            "name": "Beest"
        }
    },
    "name": "Arnoud",
    "uid": "067f010c-5580-450a-84ba-6e94880886c2"
}

Upvotes: 0

Views: 96

Answers (1)

funador
funador

Reputation: 552

That could be an expensive query as your data set grows. What about having a separate child ('groups') that stores all of your groups and in each group object you keep a reference id to each member that is a part of that group? Then you can query the data from that direction.

Upvotes: 2

Related Questions