i am building a forum-like application and i am stuck on how to structure each user's data as there are some that has to be publicly accessible (everyone's posts for a topic in one screen) and some that has to be seen by only the user himself (a section for only a user's posts named 'my posts'). How do i store the data in firebase?
Asked
Active
Viewed 83 times
1
-
Please mark the answer as 'accepted' if it has helped to solve your issue. – Mangesh Jun 15 '20 at 17:06
1 Answers
1
There are multiple ways in which this could be done, but it highly depends on your business logic that which one is right for you. One thing is for sure that, you will need to have Security Rules to control access.
Off the top of my head, you could:
- Create two different collections for private posts and public posts.
private_postswill be a sub-collection underuserdocument andpublic_postswill be collection at the same level ofuserscollection. - There will be only one collection
postsat the same level ofuserscollection, but a post will have flag to denote that it is private to author only.
I encourage you to watch this video to learn more about Data Modeling.
Mangesh
- 5,491
- 5
- 48
- 71
-
I have done so and it works, thanks! If each post has a stream of comments that i want to display under the post in the app, do i create a subcollection of comments under each post's document id? And then fetch the stream of documents under the comments subcollection and display it. – Jun 23 '20 at 04:11
-