10.2

Suppose you need to store data for a very large number of students in a distributed document store such as MongoDB. Suppose also that the data for each student correspond to the data in the student and the takes relations. How would you represent the above data about students, ensuring that all the data for a particular student can be accessed efficiently? Give an example of the data representation for one student.


We would store the student data as a JSON object, with the takes tuples for the student stored as a JSON array of objects, each object corresponding to a single takes tuple.

{
    "id": "12345",
    "name": "Shankar", 
    "dept_name": "Comp. Sci.", 
    "tot_cred": 32, 
    "takes": [
        {
            "sec_id": 1, 
            "semester": "Fall", 
            "year": 2017, 
            "grade": "C", 
            "course_id": "CS-101", 
        }, 
        {
            "sec_id": 2, 
            "semester": "Spring", 
            "year": 2017, 
            "grade": "A", 
            "course_id": "CS-190", 
        }, 
        {
            "sec_id": 1, 
            "semester": "Spring", 
            "year": 2018, 
            "grade": "A", 
            "course_id": "CS-315", 
        },
        {
            "sec_id": 1, 
            "semester": "Fall", 
            "year": 2017, 
            "grade": "A", 
            "course_id": "CS-347", 
        },  
    ]
}