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

Retrieve the value of the chosen option from a dropdown menu that adjusts dynamically within

I have a query that involves dynamically adding rows to a table for data insertion. A particular <td> element houses a dropdown menu, and I need to extract the selected value from this dropdown in order to make an AJAX call back to a PHP script that ...

Removing a dynamic component in Angular

Utilizing Angular dynamic components, I have successfully implemented a system to display toaster notifications through the creation of dynamic components. To achieve this, I have utilized the following: - ComponentFactoryResolve - EmbeddedViewRef - Ap ...

Is it possible to locate and eliminate the apostrophe along with the preceding letter?

My objective is to tidy up a character string by removing elements that are not essential for the user and SEO, specifically the (letter before the apostrophes) in this case. I am looking for a regex solution or explanation of how to achieve this in PHP, a ...

The "variable" used in the React app is not defined, resulting in a no

Following the tutorial of Mosh Hamedani, I attempted to create a react-app. You can watch the tutorial here. I followed his instructions exactly as mentioned. I encountered an issue when trying to pass an argument named product to a function called on on ...

Javascript error in formatting

Currently, I am utilizing an inner join operation on three tables and displaying the resulting table using XML. <SQLInformation> <Table>tblechecklistprogramworkpackagexref prwpxref</Table> <TableJoins> INNER JOI ...

Crawlers designed to handle websites with never-ending scroll feature

Currently seeking a crawler application that can analyze the JavaScript on a webpage for AJAX requests and identify functions that initiate those calls in order to retrieve all content from start to finish. I would develop this myself, but my workload is ...

Utilize Jquery to locate and update the text of all div elements that have an empty id attribute

I need help with a task involving a list of divs, some with ids and some without. My goal is to identify all the divs within a specific class that have empty ids and change their inner text to say "no data available". Can this be done? My attempt using $( ...

Encountering an error message that says "ERROR TypeError: Cannot read property 'createComponent' of undefined" while trying to implement dynamic components in Angular 2

I am currently facing an issue with dynamically adding components in Angular 4. I have looked at other similar questions for a solution but haven't been able to find one yet. The specific error message I am getting is: ERROR TypeError: Cannot read ...

"Ensure div remains at the bottom of the page even while

In order to implement a feature where the menu sticks to the top when scrolling down, you can use the following JS code. You can view a live example of this functionality on this Plunker by widening the preview window to see the columns side by side. wi ...

When I toggle the div to close on mobile, I want it to show on desktop

My attempt at creating a toggle button to hide and show content was not successful. I struggle with coding in Javascript/Jquery. In the desktop view, the description displays perfectly (see image here), but in mobile view, there is a button to toggle hidi ...

Unable to retrieve embedded link using fetchText function in casperjs

Exploring the capabilities of Casperjs provides a valuable opportunity to test specific functions across different websites. The website used in this scenario serves as a tutorial illustration. An interesting challenge arises with an embed code that cann ...

Retrieve a markdown file from the system and render it as a string using React.js

Is there a way to load a markdown file from the current directory as a string in my code? This is the scenario: import { State } from "markup-it" ; import markdown from "markup-it/lib/markdown"; import bio from './Bio.md' const m ...

I am interested in creating a text box that has the ability to gather user input and connect it to a search

I have been attempting to develop a text box that can collect answers and link them with the search URL. However, I am encountering issues where even though I can input text into the textbox, it is not being recognized by the script. The error message sh ...

Top recommendations for implementing private/authentication routes in NextJS 13

When working with routes affected by a user's authentication status in NextJS 13, what is the most effective approach? I have two specific scenarios that I'm unsure about implementing: What is the best method for redirecting an unauthenticated ...

Interactive real-time search results with clickable option through AJAX technology

Currently, I have implemented a live search feature that displays results based on what the user types in real time using the keyup function. However, one issue I encountered is that the displayed results inside the <div> tag are not clickable. Is th ...

Interacting with jQuery mouse events on elements below the dragged image

I'm attempting to create a drag-and-drop feature for images using jQuery. While dragging, I generate a thumbnail image that follows the mouse cursor. However, this is causing issues with detecting mouseenter and mouseleave events on the drop target pa ...

Unable to utilize Stats.js with @angular/cli version 1.4.4

Attempting to utilize @types/stats with @angular/cli following the guidance at https://github.com/angular/angular-cli/wiki/stories-third-party-lib. However, encountering a tslint error when trying to import * as STATS from 'stats.js'. [ts] Modul ...

"findByIdAndUpdate continues to work successfully even when the request body includes parameters that are not defined in

Referenced from This particular tutorial on MERN stack development... In my mongoose schema, I have defined 4 fields: const mongoose = require('mongoose'); const Schema = mongoose.Schema; let Todo = new Schema({ name: { type: String ...

Utilize Jquery to insert the text into the input or textarea field

<div class="ctrlHolder"> <label for="" id="name.label">Name</label> <input name="name" id="name" type="text" class="textInput small" /> <p class="formHint">Please enter the name of the item you are submitting</p> </di ...

Troubleshooting issue with Django development server causing HTML5 video element to become non-seekable

My Django app is currently serving a webpage with an HTML5 video element, but I've encountered a strange issue. The video.seekable property is returning a timeRanges object with a length=0, when it should actually be length=1. Unfortunately, this mea ...