In case I use mongoDB for a site that do something common like social media platform or a forum. It does the following things in descending order of frequency:
- it can list all posts in one page, and show who posts them.
- A user can posts a post, then it will be recorded that the post belongs to that user
- It can list all post a specific user posts
How should I structure that?
If I have two collections, Posts and Users.
How can I decide whether to:
Put the post_id inside User object
or
Put the user_id inside Post object?
Or both?
My intuition is that, for efficiency I can do both (so it is duplicated). It is because this can make the query simpler. But, such duplication would have some side effects like inconsistency, right?
Because I am not a database expert. I do not know if my intuition is right. thanks.