When working with Firebase, I am required to extract data from two different tables simultaneously

When working with Firebase, I have the need to extract data from tables/nodes.

Specifically, I am dealing with two tables - one called jobs and the other called organisations.

The outcome I am looking for: I want to retrieve all companies that do not have any jobs listed.

To illustrate, here is a simplified example of my jobs list node/table structure:

jobs: {
    -k3resdfsfsdfsdf:{jobName: test1, companyId: 1h3hr4jrkfk5k5kff},
    -k3resdfsfsdfsdf:{jobName: test2, companyId: 2h3hr4jrkfk5k5kff},
    -k3resdfsfsdfsdf:{jobName: test3, companyId: 2h3hr4jrkfk5k5kff}    
}

Here is a similar example of my organisations table structure:

organisations: {
    fsdfsddfsfsdfsdf:{companyId: 1h3hr4jrkfk5k5kff, companyName: comp a, address: 12 road},
    jhhjresdfsfsdfsf:{companyId: 2h3hr4jrkfk5k5kff, companyName: comp b, address: 11 road},
    hsdfskhjfsdfsdf: {companyId: 3h3hr4jrkfk5k5kff, companyName: comp c, address: 10 road}    
}

I am aiming to identify and retrieve all organisations that do not have any job listings in the jobs list. Essentially, I am seeking to cross-reference the data.

This is what I have attempted so far:

    this.firebaseBaseUrl = "hiddenForStackOverflow";

    this.refOrg = new Firebase(firebaseBaseUrl + "/organisations");
    this.refJobs = new Firebase(firebaseBaseUrl + "/jobs");

    this.refOrg .once('value', function(snapshot: any) {

            snapshot.forEach(function(orgSnapshot: any) {

                var listOfOrganisations= orgSnapshot.val();

                // I am currently unsure how to achieve this without iterating through both lists, which might lead to performance issues.

            }); 
        });

Answer №1

Include a new child node under the organizations section to link it with the available jobs

organizations
   -company0
     companyName:
     address:
     jobs:
       k3resdfsfsdfsdf: true
       k8jsmnima90djis: true
   -company1
     companyName:
     address:
   -company2
     companyName:
     address:
     jobs:
       k989ijikakmsks: true

After adding this, you will be able to search for organizations without any listed jobs using this Swift 3 code block, fetching only company1:

orgRef.queryOrdered(byChild:"jobs").queryEqual(toValue: nil)
      .observe(.value, with: { snapshot in
             print(snapshot)      
});

Alternatively,

You can maintain an open_job_count node within each company record, updating it to '0' when no jobs are available. Then query for open_job_count: 0

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

Displaying an image with a JavaScript variable is a common task in web

I have a Javascript code snippet below where the image name "samson decosta" is stored in a MySQL database. I am retrieving this image and trying to display it as a background_image in a div. document.getElementById("image_chk").style.backgroundImage="url ...

Saving the output of an AngularJS expression in an input field

Looking at the calculations below, I am currently evaluating an expression, {{ annualIncome * 4.5 }}, in one input and then re-evaluating the same expression in another input. Instead of saving the result and transferring it to the other input, I am repeat ...

I'm having trouble with my react-big-calendar not updating when I switch between day, month, or week views -

Why won't my calendar change to the week view when I click on that section? https://i.stack.imgur.com/gh2aO.png In the screenshot above, my default view is set to month, but when I attempt to switch to week, it only highlights the option without cha ...

The Chrome extension for the New Tab Page is taking the spotlight away from the address bar

It appears that with the latest version of Chrome, extensions that previously had the ability to override Chrome's New Tab Page and take focus away from the Omnibox no longer have this capability. Is there a different method now to give focus to an i ...

Invoke actions when clicking outside of components

Currently, I have a HeaderSubmenu component that is designed to show/hide a drop-down menu when a specific button is clicked. However, I am now trying to implement a solution where if the user clicks anywhere else in the application other than on this drop ...

Executing a C# method from within a .js file using a Javascript function in a .cs file

I've made some updates based on the responses provided. My main area of confusion lies in the 'data' parameter and how to handle it in the JavaScript call. C# method [HttpPost] public string GetPreviewURL(string activityID) ...

Using an array to dynamically input latitude and longitude into a weather API call in PHP

I am currently working on a leaflet map project that showcases the top 10 cities in a selected country. The markers are added dynamically based on the coordinates provided in the $latLng array. For example, when Australia is chosen from the select field, t ...

Having trouble exporting an object from a different JavaScript file in Node.js

I have been attempting to make the getCurrentSongData function retrieve the songdata object passed in from the scraper. However, I am encountering the following output: ******************TESTING**************** c:\Users\(PATH TO PROJECT FOLDER)& ...

Streamlining a complex task in JavaScript

I am currently exploring options to streamline my code so that I don't need to repeat the same function 38 times. Instead, I would like to have a single function that can handle 38 different IDs separately. The script is designed to randomly select a ...

Angular dynamically selects a dropdown option when the page is loaded

Check out this dropdown example: <div class="col-md-6"> <div class="form-group> <label class="control-label">Role</label> < ...

Is there a way in jQuery Validation to apply a rule to the entire form rather than just individual elements within the form?

I am facing an issue with a form where each element has its own custom rules that work perfectly. However, the form cannot be submitted unless values are provided for at least one of its elements. It seems like this is a rule for the entire form rather th ...

Properly configuring paths in react-native for smooth navigation

When working on my React-Native project, I noticed that my import paths look something like this: import { ScreenContainer, SLButton, SLTextInput, } from '../../../../../components'; import { KeyBoardTypes } from '../../../../../enums ...

Applying a dynamic translate3d transformation on the ::after element using CSS3

My current challenge involves manipulating a pseudo ::after element using translate3d If I hardcode the values, it's straightforward: div::after { ... transform: translate3d(40px, 40px, 0); } Now, I want to dynamically set the value for the ...

I can't understand why this question continues to linger, I just want to remove it

Is there a valid reason for this question to persist? I'm considering removing it. ...

Efficiently centering content in a grid layout using automatic fit repetition for optimized responsiveness

I've implemented a responsive grid where each item has its own hidden details section that is revealed upon clicking the item. The structure of the HTML/CSS setup is as follows: <div class="grid"> <div class="item"> ...

Determining when a text area has selected text without constant checking

class MarkdownEditor extends React.Component { constructor(props) { super(props); this.timer = null; this.startIndex = null; this.endIndex = null; } componentDidMount() { this.timer = setInterval(() => { this.setSelectio ...

I am looking to incorporate two YouTube videos into an HTML webpage, each in a different language. I would like to provide the option for users to select the language, even though the content

I am looking to target a global audience with my website, so the content is in English. However, I want to offer users the option to watch videos in their preferred language. I have recorded content in 4 different languages that might enhance engagement on ...

Can JSON be parsed using JavaScript?

Is it feasible to utilize JavaScript to parse information from an external URL hosting a JSON file on a different domain? The JSON data sample below shows various URLs with associated "q" values that I am interested in extracting. [{"url":"http://websit ...

Ways to combine X and Y velocities into a single velocity

Is there a way to combine the X and Y Velocity into a single Velocity without considering the angle? var velocityX = some value; var velocityY = some value; // Need to convert both X and Y velocities into one combined velocity ...

A specialized identifier for nested objects in a React component

I am currently working with a JSON data structure that looks like this: [ [ { city: x patients: x id: 1 }, { city: y patients: y id: 2 } ], [ { city: x patients: x id: 1 }, { city: y patients: y id: 2 } ...