One-To-Many Relationship MongoDB (WITH MILLIONS OF COMMENTS EMBEDED)

Viewed 17

I am new to MongoDB, coming from a relational database background. I have designed a post structure with many comments, but I don't know how to load them. A record is given below from that collection:

{
   _id: ObjectId("63173b1411db4b2f8e32f3cf"),
   title: "How to load data in mongoDB",
   comments: [
        {
            userId: ObjectId("63173b1411db4b2f8e32fcfb"),
            comment: "Thanks",
        },
        {
            userId: ObjectId("63173b1411db4b2f8e323fcb"),
            comment: "Nice Post",
        },
        ...
   ]
}

Now when there are hundreds of millions of comments, then how should I load them, because if I load them at once it takes a lot of time and space.

What can be the optimal solution for this?

0 Answers
Related