Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Software Requirement: . MongoDB Community Server 4.4 or higher Mongo Shell Procedures: 1. Using Mongo shell, create a database named MongoLab2 and perform the following:

image text in transcribed

Software Requirement: . MongoDB Community Server 4.4 or higher Mongo Shell Procedures: 1. Using Mongo shell, create a database named MongoLab2 and perform the following: 1.1. Create an embedded document with one-to-one relationship based on the given key elements below and insert them in "emb_customer" collections. 1.2. Create documents that have a structure of a reference data model with one-to-one relationship based on the given key elements below and insert them in "ref_customer" collections. id: 1 customername: Smith country: Philippines province: Rizal municipality: Taytay brgy: Dolores street: 286-A, Costalina 2. Perform the following: 2.1. Create an embedded document with one-to-many relationship based on the given key elements below and insert them in "emb_student collections. 2.2. Create documents that have a structure of reference data model with one-to-many relationship based on the given key elements below and insert them in "ref_student collections. id: 1 stud name: Leo school: Orca subject: Math teacher: Marcel schedule: Monday, subject: English teacher: Elinor, schedule: Tuesday, subject: Science teacher: Maritess schedule: Wednesday 3. Perform the following: 3.1. Insert the documents below in items collection. (Note: These will be the parent documents.) {"_id" : 1, "item_category": "Bag"} {"_id": 2, "item_category" : "Mobile Phones"} 3.2. Insert the documents below in inventory collection. (Note: This will be the child documents.) {"_id" : 101, "Brand": "Samsung", "Model": "Note 10", "item_id":2} {"_id" : 102, "Brand" : "HawkBag", "Model" : "HK2", "item_id" : 1} 3.3. Using the aggregate method, combine the two related documents from item and inventory collection by making the parent document as the main document; and the child as sub-document. You can use the syntax given below. db.parent_document_collection_name.aggregate(/ $lookup: from: "child_document_collection_name", localField: "key_of_parent_document", foreignField: "reference_key_in_child_document", as: "stocks" }, { $match : {parent_documents_key: "parent_documents_value" } } ]).pretty Sample output: { "_id" : 2, "item_category": "Mobile Phones", "stocks":[ "_id" : 101 "Brand": "Samsung", "Model" : "Note 10", "item_id" : 2 } ] }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions

Question

LO5 Illustrate the steps in developing a base pay system.

Answered: 1 week ago

Question

LO3 Outline strategic compensation decisions.

Answered: 1 week ago