Chapter 2: Basic Joins

Hello, Instructors!
While figuring out with rather complicated " $lookup" operator I was confused why actually we should it in this way?
I mean Why actually you’ve separated the data into two different collections (movies & comments)?
Why don’t we just store comments as a field (as an array of documents) in every Document in Movie collection?

Is it because of 16mb limit for each document in MongoDB? (We are afraid that users would write A LOT of comments for some movies and they could take more than 16mb together.)
Or because of the fact that it would be more easy to make some operations with comments (
For example, to let user to modify his comment
or to remove all the comments that were written by certain user without creating some “Multikey Indexies” beforehand)?
Or what…?

It’s not very clear for me if it would be better to store this data in one collection.

Hello @mattjavaly. Can you help me with this issue?

Hi there,

When designing your schema in MongoDB, we need to take access patterns into account. In this case, the 16MB maximum may come into play depending on the number of reviews that each movie would receive. With the reviews for movies, we may not want to pull all of the reviews every time we access the movie document as we may only be displaying the top ten reviews and not all of them so it makes sense in this case with a 1 to many relationships like this to separate the reviews into a separate collection.

Another option would be to keep a copy of a subset of the reviews in the same collection so that when accessing the movie document we could just retrieve the top comments.

Schema design is a complex topic and one that we are currently creating a course on. You should keep an eye on the University site if this is a topic that interests you.


1 Like

Thanks a lot! :+1:
I’ll keep my eye on the site!