Home > other >  Retrieve node from firebase without subnode
Retrieve node from firebase without subnode

Time:02-13

My app will display the offers for the user, and he can pick one and press join, which will send the email account to "Joiners" node.

But now my problem is I want him to see how many people have joined by counting "Joiners" node, without downloading all the emails that inside, of course.

So what I want again:

  1. Retrieve "1231qq" Node without the Emails that in "Joiners" Node.

  2. Count how many email that in "Joiners" node but without having to make the user download the whole node with other user's emails

I don't know exactly if I'm missing a technology that Firebase offer to do that kind of registration or what, so I would love some advice here, and thank you for your efforts.

Firebase snapchat

CodePudding user response:

The Firebase Realtime Database SDKs always load entire branches of the JSON. There is no way to get only a part of a node.

When you are looking for something like this, it typically means you need to heed the recommendation in the Firebase documentation to never nest multiple entity types under a single node. For example, you'll want to split the data in your screenshot over two top-level nodes like this:

Offers: {
  "1231qq": {
    done: 1231,
    name: "...",
    required: 3000,
    url: "..."
  }
},
OfferJoiners: {
  "1231qq": {
    1: "Email 1",
    2: "Email 2"
  }
}

With the above structure, you can load just the offer details without the joiner from Offers. And when needed, you perform a second call to also load that offers joiners from OfferJoiners. The extra call does not cause as much overhead as you may think, since Firebase pipelines the requests over a single connection.

  • Related