Suppose we have a MongoDB collection called Threads where it has a field of typed collection for replies to the original post.
When the user hits the reply, we would want to create a new post instance and append it to the replies field. It can be easily done as follows:
var thread = threadRepository.findById(threadId);
thread.getReplies().add(post);
threadRepository.save(thread);
But a question arises, is this solution scalable? What if there are 1 million replies to that thread?
My main question is: Will they all be loaded in memory?
If yes, wouldn't it be a waste if all we wanted to do is create a new reply? What is the recommended solution?