Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

Can I co-relate two tables with the help of a common key in MongoDB? Basically I am designing a Student Management System with the help of MongoDB and I will have one table for students and another for attendance records. 

diagram of a relational database

1 Answer

0 votes
by (107k points)
edited by

In MongoDB, there are many options available but the most basic one is to embed the attendance data into each student document. 

db.student.find( { login : "sean" } )

{

  login : "sean",

  first : "Sean", 

  last : "Hodges",

  attendance : [

    { class : "Maths", when : Date("2011-09-19T04:00:10.112Z") },

    { class : "Science", when : Date("2011-09-20T14:36:06.958Z") }

  ]

}

Using the above code it will be easier for you to retrieve the attendance data for each and every student. 

For more information regarding the same, visit this MongoDB training

Also, have a look at this professional Full Stack Development Course, designed to enhance your skills in the field.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...