Tips on fetching specific data from Firebase using Angular

Let's say I have two branches set up in Firebase, Branch A and Branch B.

Branch A :
 branchA1 :
   field1 : "Hello"
   field2 : "Hello"
branchA2 :
   field1 : "Hello"
   feild2 : "Hello"
branchA3 :
   field1 : "Hello"
   field2 : "Hello"
branchA4 :
   field1 : "Hello"
   field2 : "Hello"
branchA5 :
   field1 : "Hello"
   field2 : "Hello" 


Branch B :
 branchB1 :
   randomID1:
     Id : branchA5
   randomID2:
     Id : branchA1
   randomID3:
     Id : branchA2
 branchB2 :
   randomID1:
     Id : branchA3
   randomID2:
     Id : branchA4

If the user selects an id like branchB2, how can Angular JS be used to specifically select only branchA3 and branchA4 from branchA?

Answer №1

Break down the procedure into two simple steps for easy execution.

  1. Begin by extracting branchB2 and reviewing the IDs of its child nodes.
  2. Next, initiate a new request to gather those nodes from branch A.
// Accessing branch B2
const dbRef_B = firebase.database().ref("branchB/branchB2")
const dbVal = (await dbRef_B.once("value")).val()

// Parsing through child nodes
const branchA_Keys = Object.values(dbVal).map(b => b.Id)

// Perform individual requests for these IDs
const requests = branchA_Keys.map((key) => firebase.database().ref(`branchA/${key}`).once("value"))

// Execute all requests simultaneously using Promise.all()
const snapshots = await Promise.all(requests)
const data = snapshots.map(snap => snap.val())

console.log(data)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to implement PortalVue in multiple Vue.js single file components?

While working on Vue.js (single file components), I have discovered three methods of passing data around: local state/props, store, and utilizing PortalVue. Through my experiments with PortalVue, I successfully implemented both portal and portal-target wit ...

Guide on how to add the details of a specific id just once using PHP or jQuery

Is there a way to ensure that newly added data from SQL is only appended once? The current script I'm using displays the newly added data from SQL, but it keeps appending the same data multiple times. For example, if I add 'test by thisuser&apo ...

Having trouble with implementing forEach in Google Script

Hey there, I'm having a syntax error in my GoogleScript. This is actually my first script ever, so I'm a bit lost as to why it's not working. The main goal is to extract data from a Google sheet and use it to create labels based on a documen ...

How can I maintain the toggle state when a PHP file is reloaded inside a div?

I developed a PHP script that parses a table and loads it into a specific division: <div id ="videprinter"> <script type="text/javascript"> $(function(){ function load(){ $("#videprinter").load("videprinter.php") ...

The delete_node() function in jstree does not seem to be removing nodes

In my attempt to create a custom context menu for different nodes, I've managed to display different labels for clicks on folders or files. However, I am facing some challenges when trying to delete them. Take a look at my code snippet. Due to diffic ...

Using the named function and function parameter to call `preventDefault()` and avoid the default

I want to incorporate an e.preventDefault() call in my event listener. My function, "voteNoClick", needs to receive a parameter named "direction". How can I pass both the direction parameter and the event object into the function, allowing me to include e. ...

Wait for transition to finish before setting focus to text input

How can I ensure that the focus is automatically set to the text input field after a transition has ended? I want the user's keyboard input to immediately go into the text input field. Is it possible to achieve this using only CSS, or do I need to use ...

What is the best way to transfer a value from state to a function as a parameter?

I have been struggling to find a way to pass the value from state (personId) as a parameter to the function (fetchPersonInfo). Despite my efforts, nothing seems to be working. That's why I decided to seek your assistance on this matter. class Page ex ...

Is there a way to refresh the animation on dougtesting.net?

I'm working with the dougtesting.net library to create a spinning wheel. I've been trying to figure out how to reset the animation once it finishes, but I can't seem to find any information on it. My goal is to completely clear all states so ...

Utilizing one JavaScript file and consistent classes for multiple modals

Is it possible to have multiple modals using the same JS file, classes, and IDs? I created this code: <button id='myBtn'>Order/Discount</button> <div id='myModal' class='modal'> <div clas ...

Enhance the standard input control in Vue.js by extending it to include features such as

Incorporating vue.js: Can you enhance a standard HTML input without the need for a wrapper element? I am interested in customizing a textarea like so: Vue.component('custom-textarea', { data () => { return { } }, template: &apo ...

Code activates the wrong function

Below is a snippet of HTML and JS code for handling alerts: HTML: <button onclick="alertFunction()">Display Choose Option Modal</button> <button onclick="alertFunction2()">Display Veloce Modal</button> JS: function alertFunct ...

Display a dropdown menu when the value of another dropdown is changed using .NET 2.0

I have a dropdown selection that I would like to trigger another dropdown to display based on the selected index change. How can I achieve this using the onchange function in JavaScript? I am working on an older project using .NET 2.0, so I am unable to ...

React: Update the hidden input's value to reflect the total number of spans clicked

I have a component called Rating that displays a star rating like this: var Rating = React.createClass({ render: function () { return ( <div className="rate-line"> <div className="rate-title">{this.props ...

Pressing a key will initiate a time delay before

I have a coding challenge where I need to navigate through a sprite sheet using setTimeouts. Everything is functioning as expected, but I am curious about implementing a feature that allows me to skip frames by pressing the "m" key. Essentially, I want it ...

Capable of generating an ajax URL parameter conditionally for utilization with jQuery Validate

I am having an issue with my jQuery validation script. What I am trying to achieve is this: when a user clicks the send button, the script will determine whether to execute an if or else statement based on the last portion of a string (isAdd). Subsequently ...

Parse JSON files from a folder and concatenate them to a CSV using Node.js

Thank you for offering your help. I have a collection of JSON files located in a directory with unknown names. I need help with the following: (1) Reading all the JSON files (2) Appending the data from the JSON files to output.csv (3) Adding "-Appended" t ...

Creating a PDF from dynamic HTML and transferring it to an AWS S3 bucket without the need to download the PDF

We have created a web application using React JS where we attempted to generate a PDF. Instead of downloading or opening the PDF in a new window, our goal is to directly upload it to an AWS S3 bucket. We have researched and tried various samples but have n ...

What is the correct way to properly insert a display none attribute

I'm experiencing some alignment issues with the images in my slideshow. I used this example as a reference to create my slide: https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_dots When clicking on the next image, it seems to mo ...

Arrange items between multiple selection areas

I have two multi selects, mySelectNumberTest1 and mySelectNumberTest2. My goal is to select items in the first dropdown and then with a trigger event, populate those options into the second dropdown. In my search for a solution, I came across this link: G ...