In NoSQL, there is no way to ‘relate’ the post with the comments.

So, what do you do?

Well – you essentially store the postId and the commentId – for EACH comment (i.e. , you store post1,comment1, post1,comment2….and so on)

This storage will work – but will be optimized for one type of query (all comments for a given post)
If you have another type of search (say, all Users who commented on this article), you are screwed. You did not store the userId along with the commentId – so again, you will be back to the drawing board.

However, if all you really care about is getting all comments on a post (first type of query), you are not only set, you will have noticeably faster retrieval times (compared to the relational model). Especially as the data set gets larger and larger.

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.