mardi 14 février 2017

Firebase retrieve data from a list of children without knowing the keys (Web)

I am working on a web application that allows some users to send others push notifications. The list of users "subscribed" to any one user is stored in a firebase database, the structure is as follows;

senderUserID
    senderSubscribers
        subscriberOneID
            token: subToken
        subscriberTwoID
            token: subToken
        subscriberThreeID
            token: subToken

Basically I need to store the list of tokens in an array in order to use each of them to specify the clients receiving a push notification.

Here is my javaScript that returns the subscriber list 'Node'. In my case senderSubscribers is actually 'players'

firebase.database().ref('/users/'+currentUserId+'/players/').once('value').then(function(snapshot){
        var allPlayersNode = snapshot.val();
        console.log(allPlayersNode);
});

Console.log looks something like

firstUserID:Object
    regID: the first subscribers token
secondUserID:Object
    regID: the second subscribers token

Aucun commentaire:

Enregistrer un commentaire