0

I have been trying to do a Firebase query for my blog for many days. I have this data structure.

[{ "-M5ivrqL4XMxI3dYokP0" : { -> ID group "title" : "group stackoverflow", "members" : { "-M88aIjP1ENue0GChAE1" : { "acepted" : "1", "comment" : "lorem ipsum", "createdAt" : "24-05-2020 22:11", "idUser" : "W1fQvOYOATXIiNEj0hG07339sIe2" }, "-M95m_Tv1XnD0KlAQeXx" : { "acepted" : "1", "comment" : "lorem ipsum", "createdAt" : "05-06-2020 19:21", "idUser" : "6xo3Y3yb2KeQvjW8Csxnbcqd2xH2" }, } } }]

What I'm looking for is to bring the group and all the users with name and thumbnail to show them in an avatar component. Something like the inner join in sql, but in firebase i have not managed to get it. thanks.

Jose
  • 3
  • 2

1 Answers1

0

Firebase doesn't have an equivalent of SQL join statements. If you want to get data for two different entities (blog/members and user in your case), you have two options:

  1. Read the data for each member after you get the relevant blog.
  2. Duplicate the relevant data for each user into each blog they're a member of.

Neither of these is pertinently better than the other, although the second is more common under folks that optimize for read throughput, while the former is more common under folks that are newer to NoSQL data modeling.

Some recommended reading to get to grips with this:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    Thank you very much, I have read all the articles and now I start with the videos. Thank you. – Jose Jun 06 '20 at 23:22