How should MongoDB’s many-to-many relationship be described?

  mongodb, question

For example, the following model for selecting courses for students should not only know which courses the students have chosen, but also which students have chosen the courses. Traditional SQL is written in the following way. If it is replaced by key-value, how should it be described?

Student:
 Id
 Name
 
 Course:
 Id
 Name
 
 Relation:
 Student_Id
 Course_Id

Can be designed such that each document in the collection stores a student’s course selection data:

// students
 {
 _id: ObjectId('4e7020cb7cac81af7136236b'),
 name: "...",
 choose_lesson: [
 {_id:ObjectId('4e7020cb7cac81af71362361'),
 lesson_name: "..."
 },
 {_id:ObjectId('4e7020cb7cac81af71362362'),
 lesson_name: "..."
 }
 ]
 }

What classes did the students take?

db.students.find(
 {_id: ObjectId('4e7020cb7cac81af7136236b')},
 {choose_lesson: 1}
 )

What are the students’ choices for a course?

db.students.find(
 {choose_lesson: {$elemMatch: {lesson_name: "..."}}},
 {name: 1}
 )

ReferenceHow to design mongodb user praise function reasonably?