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.
Asked
Active
Viewed 26 times
0

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

Álex Goia
- 15
- 4
-
Are you using the Realtime Database or Firestore? – Louis Coulet Sep 13 '20 at 09:05
1 Answers
0
Firebase has three order/filter operations:
orderByKey()
orders/filters on the keys of direct child nodes, which means on the6-8-2020
,7-8-2020
in your JSON.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.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