[Solution] Week 4 : Schema Design : M101JS: MongoDB for Node.js Developers
Homework 4.1 :
Suppose we are building a web site that will display companies data in several different views. Based on the lessons in this module and ignoring other concerns, which of the following conditions favor embedding milestones (as they are in the facebook.json example) over maintaining milestones in a separate collection. Check all that apply.
Note: Schema design is as much an art as a science. If you get the answer wrong on your first attempt. Please visit the forum to discuss with your fellow students.
Solution :
Homework 4.2 :
Suppose you are working with a set of categories defined using the following tree structure. "Science" is a sub-category of "Books"; "Chemistry" and "Physics" are sub-categories of "Science"; and "Classical Mechanics" and "Quantum Mechanics" are sub categories of "Physics".
Which of the following schemas will make it possible to find() all descendants of a category using a single query. For example, all descendants of "Science" are "Chemistry", "Physics", "Classical Mechanics", and "Quantum Mechanics".
Solution : B
Books Science Chemistry Physics Classical Mechanics Quantum MechanicsFor this tree, each node is represented by a document in a collection called categories.
Which of the following schemas will make it possible to find() all descendants of a category using a single query. For example, all descendants of "Science" are "Chemistry", "Physics", "Classical Mechanics", and "Quantum Mechanics".
A)
db.categories.insertOne({"_id": "Books", "parent": 0, "left": null, "right": "Science"}) db.categories.insertOne({"_id": "Science", "parent": "Books", "left": "Chemistry", "right": "Physics"}) db.categories.insertOne({"_id": "Chemistry", "parent": "Science", "left": null, "right": null}) db.categories.insertOne({"_id": "Physics", "parent": "Science", "left": "Classical Mechanics", "right": "Quantum Mechanics"}) db.categories.insertOne({"_id": "Classical Mechanics", "parent": "Physics", "left": null, "right": null}) db.categories.insertOne({"_id": "Quantum Mechanics", "parent": "Physics", "left": null, "right": null})
B)
db.categories.insertOne({"_id": "Quantum Mechanics", "ancestors": ["Books", "Science", "Physics"], "parent": "Physics"}) db.categories.insertOne({"_id": "Classical Mechanics", "ancestors": ["Books", "Science", "Physics"], "parent": "Physics"}) db.categories.insertOne({"_id": "Physics", "ancestors": ["Books", "Science"], "parent": "Science"}) db.categories.insertOne({"_id": "Chemistry", "ancestors": ["Books", "Science"], "parent": "Science"}) db.categories.insertOne({"_id": "Science", "ancestors": ["Books"], "parent": "Books"}) db.categories.insertOne({"_id": "Books", "ancestors": [], "parent": null})
C)
db.categories.insertOne({"_id": "Classical Mechanics", "parent": "Physics"}) db.categories.insertOne({"_id": "Quantum Mechanics", "parent": "Physics"}) db.categories.insertOne({"_id": "Physics", "parent": "Science"}) db.categories.insertOne({"_id": "Chemistry", "parent": "Science"}) db.categories.insertOne({"_id": "Science", "parent": "Books"}) db.categories.insertOne({"_id": "Books", "parent": null})
D)
db.categories.insertOne({"_id": "Classical Mechanics", "children": []}) db.categories.insertOne({"_id": "Quantum Mechanics", "children": []}) db.categories.insertOne({"_id": "Physics", "children": ["Classical Mechanics", "Quantum Mechanics"]}) db.categories.insertOne({"_id": "Chemistry", "children": []}) db.categories.insertOne({"_id": "Science", "children": ["Physics", "Chemistry"]}) db.categories.insertOne({"_id": "Books", "children": ["Science"]})
E)
db.categories.insertOne({"_id": "Classical Mechanics", "children": [], "descendants": []}) db.categories.insertOne({"_id": "Quantum Mechanics", "children": [], "descendants": []}) db.categories.insertOne({"_id": "Physics", "children": ["Classical Mechanics", "Quantum Mechanics"], "descendants": ["Classical Mechanics", "Quantum Mechanics"] }) db.categories.insertOne({"_id": "Chemistry", "children": [], "descendants": []}) db.categories.insertOne({"_id": "Science", "children": ["Chemistry", "Physics"], "descendants": ["Chemistry", "Physics", "Classical Mechanics", "Quantum Mechanics"]}) db.categories.insertOne({"_id": "Books", "children": ["Science"], "descendants":
Solution : B
Homework 4.3 :
{ _id: 123456789, title: "Good Book", author: [ "Sam Goodman", "Mike Smith" ], published_date: ISODate("2010-09-24"), publisher_id: "Smith Publishing", available: 3, checkout: [ { patron_id: "33457", date: ISODate("2012-10-15") } ] }Which of the following is the primary advantage to this design?
Solution : Can make atomic updates as books are checked out or turned in.
Enjoy....!!!!
Feel free to comment below your experience with above approach and If you still find any problem with above steps Let me know I would love to help you to resolve your problem.
If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech
Related Post :
1) [SOLUTION] WEEK 1 : INTRODUCTION : M101JS: MongoDB for Node.js Developers2) [SOLUTION] WEEK 2 : CRUD : M101JS: MongoDB for Node.js Developers
3) [SOLUTION] Week 3 :The Node.js Driver : M101JS: MongoDB for Node.js Developers
4) [SOLUTION] WEEK 4 : SCHEMA DESIGN : M101JS: MongoDB for Node.js Developers
5) [SOLUTION] WEEK 5 : INDEXES AND PERFORMANCE : M101JS: MongoDB for Node.js Developers
6) [SOLUTION] WEEK 6 : THE AGGREGATION FRAMEWORK : MongoDB for Node.js Developers
7) [SOLUTION] WEEK 7 :APPLICATION ENGINEERING : MongoDB for Node.js Developers
8) [SOLUTION] FINAL EXAM(PROJECT) :MONGOMART APPLICATION : M101JS: MongoDB for Node.js Developers
You are amazing :)
ReplyDeleteThank You Very Much
Deletei read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future.. mobile truck repair
ReplyDeleteThanks For you Valuable Feedback...!!!
DeleteThanxxx
ReplyDeleteThanks For you Valuable Feedback...!!!
DeleteHi Thanks for the help, but could you explain about the first solution.
ReplyDeleteNice blog Buddy, Have you created dynamic schema using nodejs with one to many mapping?
ReplyDeleteThanx.
yes Atul
Delete