0

I have an events node, where each event has a queue full of objects with specific keys. I am trying to use my server to get the keys of all events where a queue contains a specific key, ordered by time. This is my data structure:

{
    "events" : {
        "6Pl5x3KrDgOPxwEQq5yD" : {
            "queue" : {
                "aIcQtBOGP4eAgZvxh0emaHGCMNf1" : {
                    // Details
                },
                // More queuers
             }
        },
        "08Gnr1pbCQETXeRyRG349" : {
            "queue" : {
                "8Gnr1pbCQETXeRyRG349" : {
                    // Details
                },
                // More queuers
             }
        }
    }
}

So if I was searching for all events whose queue contained the key aIcQtBOGP4eAgZvxh0emaHGCMNf1 in the data above, I would retrieve back 6Pl5x3KrDgOPxwEQq5yD.

How can I do that using Node.js?

Tometoyou
  • 7,792
  • 12
  • 62
  • 108
  • Hi there, "6Pl5x3KrDgOPxwEQq5yD" is this event Id ? or auto generated? – MuruGan Jun 13 '18 at 11:31
  • @MuruGan Yeah it is the id of the event. It is autogenerated when I create a new event. – Tometoyou Jun 13 '18 at 11:32
  • to my understanding, you have list of events and in that you have queues for events attendees. Something like that? – MuruGan Jun 13 '18 at 11:35
  • @MuruGan Yep that is correct, so I'm trying to see all the events which a person is in the queue for – Tometoyou Jun 13 '18 at 11:35
  • what best you can do is pull out the queue from the events because when you want the events alone but still you will get the queues list so it's downloading excess data. – MuruGan Jun 13 '18 at 11:38
  • First of all i want how will query the firebase.database().ref('/events/' + '/' + 'your eventId' +'/queues' + 'attendees Id'). how will you perform this ? – MuruGan Jun 13 '18 at 11:40
  • @MuruGan Ah yeah, true it'll get the whole list of data wont it. I guess I could just store the ids of the events that the user has joined somewhere else. But I would like them to be sorted by date. – Tometoyou Jun 13 '18 at 11:44
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/173066/discussion-between-murugan-and-tometoyou). – MuruGan Jun 13 '18 at 11:44

1 Answers1

0

Firebase Database can order/filter on properties that are on a known path under each child node of the location where you run the query. You're trying to filter on a dynamic path, which isn't possible.

You'll typically want to add an extra data structure to allow the lookup you want, e.g. a top-level list with the queue ids as keys, and then their event id as the value.

"events": {
    ...
},
"queues": {
    "aIcQtBOGP4eAgZvxh0emaHGCMNf1": "6Pl5x3KrDgOPxwEQq5yD",
    "8Gnr1pbCQETXeRyRG349": "08Gnr1pbCQETXeRyRG349"
}

Now you can look up whatever event somebody is queued for.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807