0

I need help figuring out how to query a database array where values equals one or more values from an input array

my main realtime-database structure looks like this:

dbName
    pushId
        categories (array)
            index (need wildcard)
                label (string i need to match)
                value (pushID from other db)

now, my problem is i cannot figure out how to get through all the children from the root - through an unknown number of category indexes - to finally find matches for each of the string in my inputArray in each of the db items...

const dbRef = ref(getDatabase(), 'dbName');

search.forEach(async (option) => {
    const searchQuery = query(dbRef,
        child('categories'), // this doesn't work!
        orderByChild('label'),
        equalTo(option.label),
    );
...

i origianally had the array as a comma ',' separated string, but the realtime-database only allows matching string equally, so i ditched that approach.

please help me

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
storm-83
  • 31
  • 6
  • Please edit your question to show the actual JSON from the database (as text, no screenshots), rather than the schematic representation of the data structure. You can get this by clicking the "Export JSON" link in the overflow menu (⠇) on your [Firebase Database console](https://console.firebase.google.com/project/_/database/data). – Frank van Puffelen Aug 13 '23 at 14:55
  • The likely solution is to add a data structure that allows the query you want, as explained here https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Aug 13 '23 at 14:56
  • i've tried rearranging my data where i now have a seperate database for searching. But how do i insert a value in key, and true in value as suggested in the link ? – storm-83 Aug 18 '23 at 11:19
  • never mind - i figured it out – storm-83 Aug 18 '23 at 12:51

0 Answers0