0

I have been using firebase for quite some time now and have hit a strange road block while trying to accomplish this query:

Here is what the node looks like in my DB:

  • Parent

    • Item

      • effects

      effect1: "effect1"

      effect2: "effect2"

      effect3: "effect3"

      effect4: "effect4"

I am trying to perform the following query to return all Items with a specific effect, let's say we want all Items that have effect3 in the effects node:

export const filterByEffect = (effect3) => {
    return (dispatch) => {
      firebase.database().ref('/strains')
        .orderByChild('effects')
        .equalTo('effect3')
        .on('value', snapshot => {
         dispatch({ type: STRAIN_FILTER, payload: snapshot.val() });
        });
    };
  };

I am getting null... I have never had a problem querying like this although it has always been for a specific string that isn't in an object structure... I appreciate any feedback and guidance!

Cheers.

hugger
  • 426
  • 4
  • 19
  • The `orderByKey()` method doesn't take any parameters, so `.orderByKey('effects')` is just `orderByKey()`. There is also no efficient way to filter items that have a certain effect. See my answer here: https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jan 28 '19 at 20:55
  • @FrankvanPuffelen my apologies! I was using orderByChild I was just playing around and didn’t review my question he’d enough before posting... – hugger Jan 28 '19 at 20:58
  • I think my question is answered from what I just saw in your answer to the other question, I’ll give it a shot when I get back in the zone - thanks Puf! @FrankvanPuffelen – hugger Jan 28 '19 at 21:05

0 Answers0