please answer this question

profileahmad959
QSIMAILAR.docx

Consider the following scenario and answer the following questions: -

Arab Open University accommodates students in various disciplines. Every Student is identified by Student Id. Student name, Contact, Address, and Department are the other details in the student collection recorded in the University. WayNo, Street, City and Country are the different sections of the address. Department details include Department Id and Department name and Contact includes Phone number and email.

1. a. Write an embedded student document schema in MongoDB as per the student details given in the above scenario. (You can use any values for the fields) [8 marks]

ANSWER

Student collection

{

_id: 125, //2 marks

studentName: “Ahmed”,

contact: { //2 marks

Phone: 24477896,

Email: “[email protected]

}

Address: { //2 marks

WayNo:85799,

Street:”xyz”,

City:”Muscat”,

Country:”Oman”

}

Department: { //2 marks

DeptID:6,

DeptName:”IT”

}

}

b. List any 1 advantage and disadvantage of embedded data model in the context of the above embedded document schema. [2 marks]

ANSWER

Embedded data models allow applications to store related pieces of information in the same database record. For example, with one query, the complete details of the student can be retrieved.

But it can lead to large documents that contain fields that the application does not need. This unnecessary data can cause extra load on your server and slow down read operations. For example, if address is not frequently accessed, it can be stored as a separate collection.

2. a. Update the above embedded student document and describe the relationships in the document using references. [8 marks]

ANSWER

Student document //2 marks – 1 mark for deptid reference

{

_id: 125,

studentName: “Ahmed”,

DeptID:6

}

Address document //2 marks – 1 mark for studentId reference

{

_id=<ObjectId1>

WayNo:85799,

Street:”xyz”,

City:”Muscat”,

Country:”Oman”,

studentId: 125

}

Department document //2 marks

{

_id:6,

DeptName:”IT”

}

Contact document //2 marks – 1 mark for studentId reference

{

_id=<ObjectId2>

Phone: 24477896,

Email: [email protected],

studentId: 125

}

b. List the advantages of using references to describe the related data in the context of the above scenario. [2 marks]

References are used to avoid duplication of data. In the above scenario, using references, we can avoid repetition of the department information in the student document. The performance of the read operation will improve when references are used. For example, if Address is not frequently used, it can be represented as a separate collection