How to create nested comments

I am creating YouTube clone how can I add comments below the video.

And one can comment on a comment and so on how to do that?

In mern stack
And I am feeling that mongodb will not be appropriate. Any other database I can use?

You could do this any number of ways. The general approach will be the same, where you have a “one to many” relationship.

MongoDb specifically can handle this relationship via lookups just like any other relational database.

However how and where you store and serve the videos themselves will be the biggest blocker and concern, as video is very resource intensive.

but what if you delete the user then all its comments need to be deleted?
How will you achieve normalization and deletion anomaliy

When you delete a user, you’ll maybe want to also delete all the comments the user made. Or you could update all the comments to point to an “anonymous” or “deleted” user. Which you do is more up to you and not forced by the technology you use.

You’d have to use 2 separate calls in this case, one for the actual user delete, and one for handling the comments. It’s possible you may need to make other calls (what about the user’s videos they upload?). So the number could rack up depending on what other features are affected.

However this should be ok, as the deletion of a user’s account is not something that happens very often, so it can be a slow operation.

1 Like