0

I am making a clone of Trello

I am trying to figure out what the best way is to get a list of all the boards that the current user is a member in.

First i thought ill have a collection like "Boards > boardId > members > userId" and just add members to that list when a new user is invited/added to the board. This way i don't have to repeat data across users and keep it all in one place, along with the title of the board. Also i could use this collection to get a list of the board members to display on top of the board.

But then i realised its pretty much impossible to query in this database. I don't know how i would query to get a list of boardIds that contain a specific userId. I tried stuff like

myFirebase.database().ref('/boards/').orderByChild('uid').equalTo(user.uid) ... but it obviously doesn't work.

Do you guys have any idea how i can solve this? is there some simple solution here that im to stupid too see..? Or do i maybe have to use a separate SQL database for this? :(

example of the database

Example picture of the database

Jordan
  • 868
  • 1
  • 8
  • 25
  • This data structure makes it easy to find the members of a specific board, but not to find the board of a specific member. To allow the latter you'll want to add an additional data structure that has the inverse mapping, like `/userBoards/$userid/$boardId`. See my answer here: https://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Jun 11 '20 at 03:16
  • Thank @FrankvanPuffelen i made it work now! Would you say it's better to do it this way or would you use Cloud Firestore instead and query for it? – user6655556 Jun 11 '20 at 14:38
  • This is the idiomatic way to do [model many-to-many relationships on Firebase Realtime Database](https://stackoverflow.com/a/41528908). On another database like Cloud Firestore you may not have to create your own duplicate data for this use-case (it depends), but you may then find other limits. – Frank van Puffelen Jun 11 '20 at 18:28

0 Answers0