0

I want to list all the elements inside session that equals to some id. I'm new on Firebase and I'm trying to understand this kind of databases.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Álex Goia
  • 15
  • 4

1 Answers1

0

Firebase has three order/filter operations:

  1. orderByKey() orders/filters on the keys of direct child nodes, which means on the 6-8-2020, 7-8-2020 in your JSON.
  2. orderByValue() orders/filters on the simple value of the direct child nodes. Since your child nodes have JSON objects as a result, this operation doesn't apply to your data structure.
  3. orderByChild(...) order/filters on the value of a named property under each direct child node. This operator won't help for your use-case, as you're looking to order/filter on a key and not a value.

This unfortunately means that isn't possibly in your current data structure. None of the orderBy operations would order/filter on the keys you want to query.


You'll need to modify the data structure to allow the use-case, which is quite common when using NoSQL databases. In your case I'd add an additional data structure that maps the push IDs back to the dates on which it was used:

"keysToDates": {
  "-MFytoo...3So": {
    "6-8-2020": true,
    "7-8-2020": true
  },
  "-MFyunx...wFs": {
    "6-8-2020": true
  }
}

Now with this additional structure, you can look up the dates for a ID, and then from there look up the series and other information. This latter load is not nearly as slow as you may initially think, as Firebase pipelines these requests across its WebSocket connection.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807