Ways to confirm the specific data in the Firebase database node

There is a JSON structure that looks like this:

    {
    "engagedUsers": {
        "qwe": {
          "agent_availability": true,
          "conv_id": "parthengineer_qwe",
          "emailId": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d1c1a082d0a000c04">[email protected]</a>",
          "login_time": 1512644440,
          "name": "qwe",
          "uid": "adasfklsfjdskldgsgjgjkl"
        },
        "tt": {
          "agent_availability": true,
          "conv_id": "genesis_tt",
          "emailId": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7d3d3e7">[email protected]</a>",
          "login_time": 1512644440,
          "name": "tt",
          "uid": "adasfklsfjdskldgsgjgjkl"
        }
      }
    }

I am trying to check if the value of the 'conv_id' child is equal to parthengineer_qwe. However, my current code is not working as expected:

this.engagedRef = firebase.database().ref('engagedUsers');
this.engagedRef.orderByValue().once('value', function (snapshot) {

    snapshot.forEach(function (data) {
      if ((data.child('conv_id').val() == 'parthengineerqwe') && (existEngageduser !== 1)) {
        existEngageduser = 1
      }
      if (existEngageduser == 1) {
        isEngaged = true
      }
    })
    return isEngaged;

  });

I am looking for a better approach to achieve this, as I want the isEngaged variable to be true. Any suggestions?

Answer №1

I'm a bit uncertain about your request, but have you considered creating an external function to handle it?

snapshot.forEach(function (data) {
    if (isEngaged(data.val())) {
      console.log(data.key, ' is engaged');
    }
}

function isEngaged(userData) {
    return (userData.conv_id === 'parthengineer_qwe') || false;
}

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

Assign the value from the list to a variable in order to execute an API call

Imagine a scenario where there's a button that displays a random joke based on a specific category. The categories are fetched using an API request from https://api.chucknorris.io/jokes/categories The jokes are generated from https://api.chucknorris. ...

Tips for accessing and adjusting an ngModel that is populated by an attribute assigned via ngFor

Looking for guidance on how to modify an input with ngModel attribute derived from ngFor, and update its value in the component. Here is my code snippet for reference: HTML FRONT The goal here is to adjust [(ngModel)] = "item.days" based on button click ...

Is it possible to move between textboxes using arrow keys in HTML?

Is there a way to navigate through textboxes using arrow keys in HTML without relying on jQuery? Possibly utilizing JavaScript, HTML, CSS, or another method? Thank you for your help! <body> <form> <input type="text"&g ...

Exploring the world of Ajax with jQuery

Could someone help me figure out how to integrate Ajax into my PHP code so that the content can load dynamically? Currently, it looks something like this: First, a user selects a category: <li><a href='?genre=sport'>Sport</a>& ...

Avoiding leaps through the use of dynamic pictures?

Currently, I am implementing the picture element along with srcset to download the same image but in varying resolutions depending on the screen size of the device. The image has a style of max-width: 100%, causing it to shift the content below when downl ...

Tips for maintaining table elements in place using JavaScript

My goal is to keep the tags within the table fixed when printing. The code I've written functions correctly in View mode, however, when printed using JavaScript, if one of the columns is too large, the rest of the columns get displaced. I want all col ...

JavaScript regex problem

As I am handling a specific string: £1,134.00 (£1,360.80 inc VAT) I am currently attempting to isolate the numerical values as follows: ['1,134.00','1,360.80'] My approach involves utilizing this regex pattern in Javascript: /&bs ...

`Python handling inheritance within complex objects loaded from JSON files`

In my project, I've implemented a dictionary that holds string keys and instances of different classes as values. Now, my goal is to serialize this data using JSON and then deserialize it back to its original objects. class A: def __init__(self, ...

Passing a ref from a parent component to a child component in reactjs

I have the following situation, how can I make sure that the attachment field in the child component is accessible from the parent component? class ServiceDeskCustomerCreate extends Component { constructor(props, context) { super(props, context); ...

AngularJS $compile function is failing to render a custom template

Hi there, I am facing an issue while trying to render a custom template using the $compile function. The error message I keep getting is: unrecognized expression: {{senddata}} I have provided my code below for reference: app.controller('MainCtrl&ap ...

Looking to increase the resolution of a 512x512 heightmap array of pixels in a png image to 2017x2017 using JavaScript for implementation as a heightmap in Unreal Engine 4?

I have a task of converting a 512 x 512 32-bit RGB PNG image with encoded height values into a 16-bit grayscale PNG representing height values for a height map. Below is the code used for this conversion: The image conversion process utilizes image-js li ...

Utilizing only select functions from lodash can be more beneficial than installing the entire library, as it reduces the amount of unnecessary dependencies

While working on my project, I incorporated underscore.js for its functionality. However, I recently discovered the need for Lodash's fill function. The idea of adding Lodash to my project seems excessive due to overlapping features with underscore.js ...

Ways to receive a POST request from an external server on a GraphQL Server

Currently, I am working on a project that utilizes GraphQL. As part of the project, I need to integrate a payment processor. When a user makes a successful payment, the payment processor sends a POST request to a webhook URL that should point to my server. ...

What causes a stack trace to be logged alongside a rejected Promise in Node version 7.2.0?

After executing this code in Node 7.2.0: let prms = Promise.reject(new Error('error')); prms.catch(() => {}); console.log(prms); I anticipated Promise {<rejected> Error: error} to be displayed on the console, however I was instead pre ...

Transitioning from Jquery to vanilla JavaScript or transforming Jquery code into pseudo code

Struggling with a snippet of jQuery code here. While I have a good grasp on JavaScript, my knowledge of jQuery is somewhat limited. I am seeking assistance to analyze the following code in order to translate it into plain JavaScript or pseudo code that ca ...

Ajax loaded scripts are unable to access global variables

Index.html <script> let bar = 1; </script> This html page is being loaded multiple times on the page using AJAX: article.html <script> if (bar === 1) { // perform a task } // Error: bar is not defined </script> Bar is a simple ...

Change the value of the checked property to modify the checked status

This is a miniCalculator project. In this mini calculator, I am trying to calculate the operation when the "calculate" button is pressed. However, in order for the calculations to run correctly in the operations.component.ts file, I need to toggle the val ...

Create and dispatch a JSON POST request to a remote domain without direct server access

My current hurdle involves attempting a POST request in JSON to an external domain without having access to the server's files for modification. However, upon making the request, I encounter the following error: XMLHttpRequest cannot load . No & ...

How can you transform a threejs perspective camera into an orthographic one?

After converting a perspective camera to an orthographic camera, I noticed that the model appears very tiny and hard to see. I have already calculated the zoom factor for the orthographic camera based on the distance and FOV, but I'm unsure if there a ...

What is the quickest way to accomplish this task?

Currently, I am in the process of constructing a dashboard using ASP.Net MVC, Angular.js, SQL Server, and Fusion charts. The data needed for charting is stored in a database and obtained through a stored procedure. My objective now is to convert the result ...