Hello guys and girls,
i am a bit of a beginner in mongodb and very insecure, how to design the schemas for my webapp (MERN-Stacks and hosted on AWS-EC2), so i would appreciate a bit feedback, if i am doing some very stupid beginner mistakes.
I want to build a social media plattform, where everyone can post texts and other can rate it and write comments.
The user should also be able to look up all their own ratings and comments in their profile(so only to put the ratings and comments in the documents of the related text seems to me wrong, otherwise i would have to „scan“ every text document, to find, where the user posted a comment or rated).
But also to duplicate all the content to put the comments and ratings into the userdocument AND the textdocument seems also be wrong (because you should avoid duplicate data, because of storage and maintain reasons).
So my design would be to have 4 different collections (Users, Texts, Ratings, Comments).
If now someones open a text, i would grab every comment and rating, that have a ref from the requested text.
If then some user looks up his own comments or ratings i would grab every comment or rating, that have a ref to from the user.
Is this fine? Or would it need to much processor power? For me it seems a bit „strange“ to look everytime, every comment or rating! But i heard, that the mongodb is very fast to look up complete collections (even big ones) and only cost very low processor power. I am bit of a nooby.
I am also thinking about using a hybrid-approach and to add the first 10 comments also in the related text document and add the average rating (and only update the last one every 3 hours). Is this necessary for 1000 or even 10k users?
The next but small question is: I want to show the name author of the text, but with the ref-command of mongodb i am only having the user_id of author (So, then I would have to search all users and assign the particular user_id to the authorname or username, everytime i display a text). Would it make sense also to add the authorname to the textdocument and also only update it manually in the backend every 12 hours? Or i am overestimating the necessary processor power again?
Thanks for your feedback and advices.