"how to retrieve multiple data in one query firebase" Code Answer


there are a couple of directions to go with this.

one option is to read in your team node, separate out the player refs into perhaps an array and then iterate over the array to get each player ref and load each player with a separate firebase call

a better option is to store a reference back to the team in each player's node

 "players" : {
      "jojo-pti-gros" : {
         team: "-kbhfh9u3cxqpzics5ru"

observe the teams node to load in the team data then then query the players node for all players that have a child: team = "-kbhfh9u3cxqpzics5ru"

firebase *playersref = [myrootref childbyappendingpath:@"players"];
fquery *query1 = [playersref queryorderedbychild:@"team"];    
fquery *query2 = [query1 queryequaltovalue:@"-kbhfh9u3cxqpzics5ru"];

[query2 observeeventtype:feventtypevalue withblock:^(fdatasnapshot *snapshot) {

    nslog(@"key: %@    %@", snapshot.key, snapshot.value);


the result will be a snapshot filled with all of the players that belong to the team.

By ChaosTheory on March 24 2022

Answers related to “how to retrieve multiple data in one query firebase”

Only authorized users can answer the Search term. Please sign in first, or register a free account.