Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab: Apply the Polymorphic Pattern #1

Open
iZoom786 opened this issue Nov 5, 2022 · 0 comments
Open

Lab: Apply the Polymorphic Pattern #1

iZoom786 opened this issue Nov 5, 2022 · 0 comments

Comments

@iZoom786
Copy link

iZoom786 commented Nov 5, 2022

mongodb-university-courses/M320: Data Modeling/Chapter 4: Patterns (Part 2)/

The Question Has been changed , so 5caab67a9c0aa5e39686f806 is not correct abswer

Pl. Help to provide new validation code.

Problem:

User Story

Our company has been selling books online for many years.

Recently, we decided to expand and acquired the rights to sell the books as ebooks and as audiobooks.

Currently, the books in our catalog look like this:

{
"_id": ObjectId("5caa9e799c0aa5e39686f000"),
"product_id": 34538756,
"title": "MongoDB: The Definitive Guide: Powerful and Scalable Data Storage",
"description": "MongoDB explained by MongoDB champions",
"authors": ["Shannon Bradshaw", "Eoin Brazil", "Christina Chodorow"],
"publisher": "O'Reilly",
"language": "English",
"pages": 514,
"catalogues": {
"isbn10": "1491954469",
"isbn13": "978-1491954461"
}
}

The following two documents are respectively the representations of the above book as ebook and audiobook from our two suppliers of these formats:

[{
"_id": ObjectId("5caa9e799c0bb5e39687f000"),
"title": "MongoDB: The Definitive Guide: Powerful and Scalable Data Storage",
"desc": "MongoDB explained by MongoDB champions",
"authors": ["Shannon Bradshaw", "Eoin Brazil", "Christina Chodorow"],
"publisher": "O'Reilly",
"language": "English",
"eformats": {
"epub": {
"pages": 774
},
"pdf": {
"pages": 502
}
},
"isbn10": "1491954469"
},{
"_id": ObjectId("5cbb9e799c1aa5e39686f000"),
"title": "MongoDB: The Definitive Guide: Powerful and Scalable Data Storage",
"desc": "The complete book of MongoDB by its employees",
"author": "Eoin Brazil",
"narrator": "Eoin Brazil",
"publisher": "O'Reilly",
"language": "English",
"length_minutes": 1200
}]

We decided to put all the documents, one per media type, in the same collection to minimize the impact on the current applications.

As we retrieve a document, we can forward the information about the product to the right Web page to render the information about the book in a given format.

Task

To address the schema changes, we will use the Polymorphic Pattern to identify the shape of each document depending on its format.

We will make the following modifications to our current schemas to have all documents share some common elements:

Across all documents, we will use a new field called format that will have a value of book, ebook, or audiobook.
Across all documents, we will have a field called product_id that will accept an integer as its value.
The field description should be unified across all documents.
The field authors should be unified across all documents.
To complete this task, complete the following steps:

Modify the following schemas to incorporate the changes stated above:

[{
"_id": "",
"product_id": "",
"title": "",
"description": "",
"authors": [""],
"publisher": "",
"language": "",
"pages": "",
"catalogues": {
"isbn10": "",
"isbn13": ""
}
}, {
"_id": "",
"title": "",
"desc": "",
"authors": [""],
"publisher": "",
"language": "",
"eformats": {
"epub": {
"pages": ""
},
"pdf": {
"pages": ""
}
},
"isbn10": ""
},{
"_id": "",
"title": "",
"desc": "",
"author": "",
"narrator": "",
"publisher": "",
"language": "",
"length_minutes": ""
}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant