I want to create a system of user reviews and replies to the reviews in a website. There can be replies to replies. I'm using mongodb database which I think is an important detail.
The review document looks roughly like this:
The reply object looks like this:
I'm not sure which route to take with how to store user replies. On the one hand it will be super convenient to store an array of reply objects in the review document (1). On the other hand I feel it will be more stable and organized to save replies as separate documents in the db (2).
In case 1 I get the benefit of mongodb flexibility and I will not need to make db lookups.
In case 2 I thought to add
previous: ObjectId and
next: ObjectId fields to each reply. Then the review will only be linked to the first reply in the chain. In case 2 there will be more lookups for replies as I will have to iterate
next all the time. It won't take a lot of time to get the next reply though because mongodb creates an index by default on id fields. Another disadvantage is that in order to count the number of replies per review I will need to make as many db lookups to db as there're replies unless I keep the count as a field in review and make sure to increment/decrement it each time (more complexity).
So on the face of it the first route is better in terms of performance. The main disadvantage of it is that replies order is a bit volatile in the sense that it's just an array. I also instinctively feel the first route is "flimsy" because the replies are not an actual document in the db without their own id.
I'm looking for suggestions on what the best practice would be here.