Exploring paths deep within by employing wildcards as a query

I have data structured according to Firebase's flat structure advice, storing quotes in nodes like this:

quotes -> clientName -> quoteObject

Each 'quoteObject' includes a 'dateCreated' value that I aim to retrieve as follows (when fetching a comprehensive list of quotes for a specific page and consolidating them into a single array of objects):

  const quotesRef = firebase.database().ref('quotes');
    quotesRef.orderByChild('dateCreated').on('value', snapshot => {
       // function
    });

The issue arises when attempting to query the 'dateCreated' value located more than one level deep. While deep path queries are feasible with parent path knowledge, my situation involves uniquely named parent paths ('clientName'). Is there a way to specify a wildcard path in this case? If so, how can it be achieved? Thank you!

Edit: Including database example for clarification.

quotes
    - ClientEmailOne
        -UniqueQuoteID
            - createdBy: ClientEmailOne
            - dateCreated: 1479255005172
            - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="06656a6f63687275436b667877732e9c9890">[email protected]</a>"
    - ClientEmailTwo
        -UniqueQuoteID
            - createdBy: ClientEmailTwo
            - dateCreated: 1479255005172
            - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9bf8f7f2fef5efe8defafbefbeb1fbfafbcffffbefbf4fbfaaffefafbfcfffbbabfeffaeb4effdffd29dfbe69df3">[email protected]</a>"
     - ClientEmailThree
         -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7b1817121e150f083ee9eceae4edcffeecaaede2fbedeaeadce4e2eaffeded8eecf18cef7">[email protected]</a>"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c4a7a8ada1aab0b781acbdc9bdbdd2bdabb7afa8afc4adaf">[email protected]</a>"
        -UniqueQuoteID
            - createdBy: ClientEmailThree
            - dateCreated: 1479255005172
            - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9efdf2f7fbf0eaeddbf9fdfbffffdaccdcbcfaca7cdcfdedadccfccafdadecebcfbdadecd20f7ecfedcffbad7d0">[email protected]</a>"

Answer №1

When running a query in Firebase, it will search through the children of the specified location. The child you choose to order or filter by can include a path to a property, but it cannot contain any wildcards.

Update:

In your updated data structure, it appears that you are attempting to query across all clients and quotes for each client. However, this includes two wildcards ("all clients" and "all quotes"), which is not allowed in Firebase's querying model.

Your current model supports querying all quotes for a specific client:

ref.child("quotes").child("ClientEmailOne").orderByChild("dateCreated")

If you wish to query all quotes across all clients, you will need to create a data structure that includes all quotes regardless of their client:

allquotes
    -UniqueQuoteID
        - createdBy: ClientEmailOne
        - dateCreated: 1479255005172
        - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ef8c83868a819b9caa828e8683af8a978e829f838ac18c8082">[email protected]</a>"
    -UniqueQuoteID
        - createdBy: ClientEmailTwo
        - dateCreated: 1479255005172
        - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddbeb1b4b8b3a9ae98b0bcb4b19db8a5bcb0adb1b8f3beb2b0">[email protected]</a>"
     -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16757a7f73786265537b777f7a56736e777b667a733875797b">[email protected]</a>"
    -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7516191c101b01063018141c1935100d14180519105b161a18">[email protected]</a>"
    -UniqueQuoteID
        - createdBy: ClientEmailThree
        - dateCreated: 1479255005172
        - email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fd9e91949893889eb8909c9491bd98859c908d9198d39e9290">[email protected]</a>"

After setting up this structure, you can then query as follows:

ref.child("allquotes").orderByChild("dateCreated")

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

Troubleshooting problems with a JavaScript game that involves guessing numbers

I have been given a challenging Javascript assignment that involves using loops to create a counting betting game. The concept is simple: the User inputs a number, and the computer randomly selects a number between 1 and 10. The User can then bet up to 10 ...

Struggling with creating and exporting TailwindCSS and NextJS

I'm encountering challenges in constructing and exporting my TailwindCSS and NextJS project. While everything works smoothly when running `npm run dev` with all Tailwind classes functioning properly, I face an issue when executing `npm run build && np ...

Is there a way to adjust the font size in Javascript/Html without changing the color?

I have a code snippet that creates a button to increment a variable, and I want to change the font size of the displayed variable. This code is for a game akin to cookie clicker. <div class="game-object"> <script type="text/javascript>"; var c ...

Is there a way to create a Vue component that can process dynamic formulas similar to those used in

I am looking to create a component that has the ability to accept different formulas for computing the last column. The component should use these formulas in Vuex getters to store the total state values passed to it. Here are the specifications for the c ...

The request to register at http://localhost:3000/api/auth/register returned a 404 error, indicating that the

I've successfully set up a backend for user registration authentication, which works fine in Postman as I am able to add users to the MongoDB. However, when trying to implement actual authentication on localhost:3000/frontend, I encounter an error dis ...

What is the best way to supply JSON data to the "The Wall" MooTools plugin while feeding?

I came across this amazing plugin called "The Wall" but unfortunately, neither the documentation nor the examples demonstrate how to utilize JSON objects with it. Imagine we have a JSON array like: [ { href : "/my/photo/image1.jpg", title : "Me an ...

Customizing the design of vuetify table header to your liking

My goal is to implement a custom style for v-data table headers using the fixHeader method. The CSS code is intended to keep the header fixed in place even when scrolling horizontally. The issue arises as the style is applied to the inner <span> ele ...

Exploring the Brilliance of MVC PHP/AJAX

I am currently in the process of developing a PHP website that will showcase statistics derived from an external source. To illustrate how the MVC (Model-View-Controller) architecture will be implemented, I have created this unique diagram. As someone wh ...

Exploring the importance of defining a JSONP callback function

I am relatively new to JavaScript and struggling with an issue in my code. My code includes an Ajax request to a server, and I receive a response from it. Due to the cross-domain nature of the request, I am utilizing JSONP. $.ajax({ url: "***", c ...

Custom hooks in Next.js do not have access to the localStorage object

I've encountered an issue with my custom useLocalStorage hook. It works perfectly fine with create-react-app, but when I try to use it with Next.js, the value in the initial state on line 3 returns undefined. Is there a way to bypass server-side rend ...

What could be the reason for Object.assign failing to update a key in my new object?

Function handleSave @bind private handleSave() { const { coin, balance } = this.state; console.log('coin', coin); console.log('balance', balance); const updatedCoin = Object.assign({ ...coin, position: balance }, coi ...

Issue: The function (0, react__WEBPACK_IMPORTED_MODULE_1__.useActionState) is not recognized as a valid function or its output is not iterable

I found a great example of using useActionState at this source. Currently, I am implementing it in my project with Next.js and TypeScript. app/page.tsx: "use client"; import { useActionState } from "react"; import { createUser } from ...

The Vue.js application is experiencing issues with displaying Google Maps functionalities

I have developed an application using Vue.js in Monaca and Cordova with onsenUI. My goal is to display my location on a Google map within the page. I attempted to achieve this by utilizing the npm package named vue2-google-maps, but unfortunately, it' ...

How can I attach a click event to the left border of a div using jQuery?

I am wondering about a div element <div id="preview"> </div> Can anyone suggest a method to attach a click event specifically to the left border of this div? Your help is greatly appreciated. ...

Tips on sending references from child to parent components in ReactJS

Upon rendering my child component, I aim to focus on the input box right away. To achieve this, I am attempting to pass the ref of the input box up to its parent component, which contains a modal. My goal is to focus on the input field upon entering the mo ...

Matching a regular expression pattern at the beginning of a line for grouping strings

One of my tasks involves working with a markdown string that looks like this: var str = " # Title here Some body of text ## A subtitle ##There may be no space after the title hashtags Another body of text with a Twitter #hashtag in it"; My goal ...

A straightforward Node.js function utilizing the `this` keyword

When running the code below in a Chrome window function test(){ console.log("function is " + this.test); } test(); The function test is added to the window object and displays as function is function test(){ console.log("function is " + this.tes ...

Access to Firebase using Google authentication is currently restricted (permission denied)

Currently, I am utilizing Firebase to authenticate users with Google in my Angular project, "project1." When signing anonymously into Firebase, everything runs smoothly. However, if I attempt to sign in with Google using the popup feature, an error occurs: ...

What is the best way to dynamically render classes based on conditions in a table using React Bootstrap?

I am looking for a way to dynamically change the color of a class based on the transaction data in a table. import React from "react"; import Table from "react-bootstrap/Table"; import "./TableComponent.css"; const TableComponent = ({ Movement }) =&g ...

Is it possible to create my TypeORM entities in TypeScript even though my application is written in JavaScript?

While I find it easier to write typeorm entities in TypeScript format, my entire application is written in JavaScript. Even though both languages compile the same way, I'm wondering if this mixed approach could potentially lead to any issues. Thank yo ...