1

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?

1 Answers1

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:

  1. Create two different collections for private posts and public posts. private_posts will be a sub-collection under user document and public_posts will be collection at the same level of users collection.
  2. There will be only one collection posts at the same level of users collection, 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
  • Sure. That sounds logical. – Mangesh Jun 23 '20 at 07:56