Many to many relationship in MongoDB when we have specific fields

203 views Asked by At

As this article suggests for many-to-many relationship we can save objectId on both collections(lets say user, course). The problem is that I have some specific fields for user who has taken the course like his progress on this course. In the above approach it cannot help much.

I've also read this useful stackoverflow question, but here clicks is a top-level entity and has its own collection.

I have course & user collections and I have specific field like user_progress_on_course, purchased_on, user_notes, etc.

The question is should I take the SQL approach to have junction table to store fields mentioned above?


EDIT1:
One of the approaches can be as below, having user_course collection:
User course collection

The other approach is to embed user_course into user collection. As each user has at most 100 course which is ok to have then inside of user collection. So this design can be as below:

Embedded document for course in user collection

Now how do you suggest designing collections? What approach do you take? why?

0

There are 0 answers