Thursday, November 10, 2016

[Solution] Week 4 : Schema Design : M101JS: MongoDB for Node.js Developers

 [Solution] Week 4 : Schema Design : M101JS: MongoDB for Node.js Developers


Homework 4.1 : 


When using find() in the Node.js driver, which of the following best describes when the driver will send a query to MongoDB?Please review the data model for the Crunchbase companies data set. The document from this collection for Facebook is attached in the handout for convenience. Documents in this collection contain several array fields including one for "milestones".

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".

Books
    Science
        Chemistry
        Physics
            Classical Mechanics
            Quantum Mechanics
For 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

MongoDB solution for m101js Homework 4.2 for Node.js Developer,Visionfortech







Homework 4.3 :


Suppose you are working with a library catalog system containing collections for patrons, publishers, and books. Book documents maintain a field "available" that identifies how many copies are currently available for checkout. There is also a field "checkout" that holds a record of all patrons that are currently borrowing a copy of the book. For example, the document below indicates that the library owns four copies of "Good Book". Three are currently available for checkout. One has been checked out by patron "33457".

{
    _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.

MongoDB solution for m101js Homework 4.3 for node.js Developer,visionfortech
















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 Developers

2) [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

11 comments:

  1. You are amazing :)

    ReplyDelete
  2. i 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

    ReplyDelete
  3. Hi Thanks for the help, but could you explain about the first solution.

    ReplyDelete
  4. I want to thank you for writing this article.This is great Article for me. It also more very informative & awesome. I expect more articles from you in future.
    node.js development Sydney

    ReplyDelete
  5. More project we see the pipe is must for all construction for more check the pipe threading machine manufacturers.

    ReplyDelete
  6. Nice blog Buddy, Have you created dynamic schema using nodejs with one to many mapping?
    Thanx.

    ReplyDelete

Protected by Copyscape