DEV Community

Discussion on: How do you handle many-to-many relationships in Mongo?

 
nguyenthanhuet profile image
Alex

Hi,
"We can also store list of student IDs in course document. Then the time complexity should be N or o(1) as mongo creates indexes on id."
=> This makes the insert function more complicated ? If you want to add 1 students with 10 courses, you will must insert user_id to courses.student_list (apply with all of 10 courses) and insert 10 course_id to students.course.
Everything has its price, sometimes you have to accept the complexity?