0

I am using Firebase Realtime Database. Below I enclose my firebase structure:

Firebase structure

I am trying to recive all IDs where tags are equal to my payload(e.g. Phones)

I tried following query

firebase.database().ref('Questionnaires').orderByChild('tags').equalTo(payload).once("value")
        .then((data) => {
          commit('setLoading', false)
          console.log("Result", data.val())
        })
        .catch((error) => {
          commit('setLoading', false)
          console.log(error)
        })

But in effect I am reciving data.val() = null

I tried various approaches but still got null

Is it possible to construct that query with that data structure ? If yes please teach me. I am out of ideas.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Tour `tags` node doesn't have a child key matching your `payload`, so this query won't work. Your current data structure makes it easy to look up the tags for a questionnaire, but it does not make it easy to look up the questionnaires for a tag. To allow the latter, you'll want to add a secondary data structure `tags` and store the tag name and all questionnaire IDs under that. See https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen May 20 '20 at 00:47
  • Thank You Frank, your link and answer has opened my eyes. – Michal Kaczmarski May 20 '20 at 01:00

1 Answers1

-1

I've heard relationships is a nightmare to maintain in firebase, my guess is that tags is another firebase collection? If so, switch over to another dbsm before it is too late.

Burger
  • 24
  • 1