[Solution] Week 3 :Schema Design : M101P: MongoDB for Developers

 [Solution] Week 3 :Schema Design : M101P: MongoDB for Developers

Homework 3.1 : 

Download the students.json file from the Download Handout link and import it into your local Mongo instance with this command:

mongoimport --drop -d school -c students students.json

This dataset holds the same type of data as last week's grade collection, but it's modeled differently. You might want to start by inspecting it in the Mongo shell.

Write a program in the language of your choice that will remove the lowest homework score for each student. Since there is a single document for each student containing an array of scores, you will need to update the scores array and remove the homework.

Remember, just remove a homework score. Don't remove a quiz or an exam!

Hint/spoiler: With the new schema, this problem is a lot harder and that is sort of the point. One way is to find the lowest homework in code and then update the scores array with the low homework pruned.

To confirm you are on the right track, here are some queries to run after you process the data with the correct answer shown:

Let us count the number of students we have:

use school
The answer will be 200.

Let's see what Tamika Schildgen's record looks like once you have removed the lowest score:

db.students.find( { _id : 137 } ).pretty( )
This should be the output:

    "_id" : 137,
    "name" : "Tamika Schildgen",
    "scores" : [
            "type" : "exam",
            "score" : 4.433956226109692
            "type" : "quiz",
            "score" : 65.50313785402548
            "type" : "homework",
            "score" : 89.5950384993947
To verify that you have completed this task correctly, provide the identity (in the form of their _id) of the student with the highest average in the class with following query that uses the aggregation framework. The answer will appear in the _id field of the resulting document.
db.students.aggregate( [
  { '$unwind': '$scores' },
      '_id': '$_id',
      'average': { $avg: '$scores.score' }
  { '$sort': { 'average' : -1 } },
  { '$limit': 1 } ] )

Solution : 13

Homework 3.1 week-3 Mongodb For Developers,m101p,visionfortech

Homework 3.2 : 

In this homework you will be enhancing the blog project to insert entries into the posts collection. After this, the blog will work. It will allow you to add blog posts with a title, body and tags and have it be added to the posts collection properly.

We have provided the code that creates users and allows you to login (the assignment from last week). To get started, please download hw3-2and3-3.zip from the Download Handout link and unpack. You will be using these files for this homework, and for HW 3.3.

The areas where you need to add code are marked with XXX. You need only touch the BlogPostDAO.py file. There are three locations for you to add code for this problem. Scan that file for XXX to see where to work.

As a reminder, to run your blog you type

python blog.py

To play with the blog you can navigate to the following URLs

You will be proving that it works by running our validation script as follows:

python validate.py
You need to run this in a separate terminal window while your blog is running and while the database is running. It makes connections to both to determine if your program works properly. Validate connects to localhost:8082 and expects that mongod is running on localhost on port 27017.

As before, validate will take some optional arguments if you want to run mongod on a different host or a use an external webserver.

This project requires Python 2.7. The code is not 3.X compliant.

Ok, once you get the blog posts working, validate.py will print out a validation code for HW 3.2.
Please enter it below, exactly as shown with no spaces.

Solution : 89jklfsjrlk209jfks2j2ek

Homework 3.2 week-3 Mongodb For Developers,visionfortech

Homework 3.3 :

In this homework you will add code to your blog so that it accepts comments. You will be using the same code as you downloaded for HW 3.2.

Once again, the area where you need to work is marked with an XXX in the blogPostDAO.py file. There is just one location that you need to modify. You don't need to figure out how to retrieve comments for this homework because the code you did in 3.2 already pulls the entire blog post (unless you specifically projected to eliminate the comments) and we gave you the code that pulls them out of the JSON document.

This assignment has fairly little code, but it's a little more subtle than the previous assignment because you are going to be manipulating an array within the Mongo document. For the sake of clarity, here is a document out of the posts collection from a working project.

    "_id" : ObjectId("509df76fbcf1bf5b27b4a23e"),
    "author" : "erlichson",
    "body" : "This is a blog entry",
    "comments" : [
            "body" : "This is my comment",
            "author" : "Andrew Erlichson"
            "body" : "Give me liberty or give me death.",
            "author" : "Patrick Henry"
    "date" : ISODate("2012-11-10T06:42:55.733Z"),
    "permalink" : "This_is_a_blog_post_title",
    "tags" : [
    "title" : "This is a blog post title"
where post_slug is the permalink. For the sake of eliminating doubt, the permalink for the example blog post above is http://localhost:8082/post/This_is_a_blog_post_title

You will run validation.py to check your work, much like the last problem. Validation.py will run through and check the requirements of HW 3.2 and then will check to make sure it can add blog comments, as required by this problem, HW 3.3. It checks the web output as well as the database documents.

python validate.py
Once you have the validation code, please copy and paste in the box below, no spaces.

Solution : jk1310vn2lkv0j2kf0jkfs

Homework 3.3 week-3 Mongodb For Developers,visionfortech


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


  1. could u explain how to do them .How did u get at the solutions

    1. I went through this certification course and i personally solved this question and i just wrote it..
      Hope you will get your answer.
      Please let me know if you need more information.

      Pratik Soni


Post a Comment