0

I have a problem using Firebase. Probably it depends on how I structured the db but I don't know which could be a better way to do it. I pose you the schema :

What I would like to query is : give me all the list (children of list) where the userid has a child whit the key id1. What I expect is to receive idList1 and idList2.

I found other similar questions but I don't known how to apply to my problem. thank you in advance.

ozzem
  • 294
  • 1
  • 3
  • 16
  • Firebase can order/filter on an individual property that is at a fixed path under each child of the location where you run the query. Your property is at a dynamic path, so it can't be queried. Furthermore it would require you to define indexes for all UIDs, which is not feasible. See my [answer on double nesting](https://stackoverflow.com/q/27207059) and my [answer on categorization](http://stackoverflow.com/q/40656589) for longer explanations. – Frank van Puffelen Feb 17 '18 at 19:34
  • Thanks for the answer. Even if I read your posts I'm still not able to understand how to solve my own problem. If I know the idLists (by the user for example), how I could query all the lists concurrently? something like "Where idLists in (idLists1,idLists2)". My tarthaget is to show a recyclerview with all the lists where my id is in. thanks – ozzem Feb 17 '18 at 21:00
  • You can't query your current data structure to get those results. You'll need to change/augment your data structure to allow the use-case. For example: you want to get all the list ids that a given user id is part of. In that case, store precisely that in your table: for each user the collection of list ids that they're a part of. With that data in place, reading it becomes very simple. You'll see that regularly in NoSQL databases: you change your data model to fit your needs, and often store data multiple times. – Frank van Puffelen Feb 18 '18 at 06:31

0 Answers0