1

Hello I am trying to pull multiple objects with a variety of query searches and I am wondering how to do that without making multiple "orderBy" points of entry and equal to points of entry.

here is the data I have

    {
      Item: {
        IDNumber1: {
          productDepartment: Cullinary,
          productStore: JCPenny
        }
        IDNumber2: {
          productDepartment: Cullinary,
          productStore: Macys
        }
        IDNumber3: {
          productDepartment: Home,
          productStore: JCPenny
        }
        IDNumber4: {
          productDepartment: Ties,
          productStore: JCPenny
        }
        IDNumber5: {
          productDepartment: Cullinary,
          productStore: Macys
        }
        IDNumber6: {
          productDepartment: Cullinary,
          productStore: Dillards
        }
        IDNumber7: {
          productDepartment: Ties,
          productStore: Dillards
        }
      }
    }

If I wanted to pull all the objects that contain Macys Ties and Dillards so different object Items like in this case productStore and productDepartment I was wondering how to orderByChild the variety of Item names and equal it to the data that I am trying to pull.

    const query = dataFirebase.ref("jobs");
    query.orderByChild('productName').equalTo('Home').on('child_added', function(snapshot) { 


        var test = snapshot.val();
        console.log(test)
  }

I am wondering if it is a good Idea to use something like

    const query = dataFirebase.ref("jobs");
    query.orderByChild('productName','productDepartment').equalTo('Home','Dillards').on('child_added', function(snapshot) { 


        var test = snapshot.val();
        console.log(test)
  }
Jaffer Abyan Syed
  • 129
  • 1
  • 2
  • 11
  • I think you might be better off using Firestore; something like this can be done with Realtime Database, but it involves managing your own indexes – https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Callam Jan 11 '19 at 17:29
  • As Callam said, the Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For your data that could for example be: `"productStore_productDepartment": "Dillards_Ties"`. For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase (that Callam also linked). Firestore pretty much automates this index-creation process, so is definitely good to check out. – Frank van Puffelen Jan 11 '19 at 17:57

0 Answers0