1

I am trying to query the following structure:

Firebase Realtime DB

I need to find all the orders that has the path 'orders/stores{id1}' for example

I have tried the following code snippets:

return this.db.list(`orders`, ref => ref.child(`stores/id1`)).snapshotChanges();

return this.db.list(`orders`, ref => ref.child(`stores`).child(`id1`).snapshotChanges();

return this.db.list(`orders`, ref => ref.child(`stores`).equalTo('id1')).snapshotChanges();

But none have provided any results.

Should i restructure my data? Is there a way to query this?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
ShortCutNinja
  • 31
  • 1
  • 3
  • How do you initialize `ref` that you use in this snippet? – Frank van Puffelen Jun 16 '18 at 23:32
  • But it seems that you're trying to find orders for a store, where your current data structure only allows efficient querying of stores for an order. To allow your use-case, consider adding an inverse lookup structure: `/stores/$storeid/orders/$orderid`. See my longer explanation here: https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jun 16 '18 at 23:34
  • @FrankvanPuffelen I have such a lookup in my dB. Just wondered if the query was possible in such a way. Thanks – ShortCutNinja Jun 17 '18 at 07:41

0 Answers0