Monday, 11 September 2017

WEEK 6 :APPLICATION ENGINEERING : M101P: MONGODB FOR DEVELOPERS


Homework 6.1

Which of the following statements are true about replication in MongoDB? Check all that apply.

Solution : Here you find updated answer with two possible outcomes as follow


Homework 6.2

Let's suppose you have a five member replica set and want to assure that writes are committed to the journal and are acknowledged by at least 3 nodes before you proceed forward. What would be the appropriate settings for w and j?
Solution : 


Homework 6.3

Which of the following statements are true about choosing and using a shard key?

Solution : There are three possibly true statement for this homework.




Homework 6.4

You have a sharded system with three shards and have sharded the collections "students" in the "school" database across those shards. The output of sh.status() when connected to mongos looks like this:

mongos> sh.status()
--- Sharding Status ---
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5531512ac723271f602db407")
}
  shards:
    {  "_id" : "s0",  "host" : "s0/localhost:37017,localhost:37018,localhost:37019" }
    {  "_id" : "s1",  "host" : "s1/localhost:47017,localhost:47018,localhost:47019" }
    {  "_id" : "s2",  "host" : "s2/localhost:57017,localhost:57018,localhost:57019" }
  balancer:
    Currently enabled:  yes
    Currently running:  yes
        Balancer lock taken at Fri Apr 17 2015 14:32:02 GMT-0400 (EDT) by education-iMac-2.local:27017:1429295401:16807:Balancer:1622650073
    Collections with active migrations:
        school.students started at Fri Apr 17 2015 14:32:03 GMT-0400 (EDT)
    Failed balancer rounds in last 5 attempts:  0
    Migration Results for the last 24 hours:
        2 : Success
        1 : Failed with error 'migration already in progress', from s0 to s1
  databases:
    {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
    {  "_id" : "school",  "partitioned" : true,  "primary" : "s0" }
        school.students
            shard key: { "student_id" : 1 }
            chunks:
                s0  1
                s1  3
                s2  1
            { "student_id" : { "$minKey" : 1 } } -->> { "student_id" : 0 } on : s2 Timestamp(3, 0)
            { "student_id" : 0 } -->> { "student_id" : 2 } on : s0 Timestamp(3, 1)
            { "student_id" : 2 } -->> { "student_id" : 3497 } on : s1 Timestamp(3, 2)
            { "student_id" : 3497 } -->> { "student_id" : 7778 } on : s1 Timestamp(3, 3)
            { "student_id" : 7778 } -->> { "student_id" : { "$maxKey" : 1 } } on : s1 Timestamp(3, 4)


Solution : S1



Homework 6.5

In this homework you will build a small replica set on your own computer. We will check that it works with validate.py, which you should download from the Download Handout link.
Create three directories for the three mongod processes. On unix, this could be done as follows:

mkdir -p /data/rs1 /data/rs2 /data/rs3

Now start three mongo instances as follows. Note that are three commands. The browser is probably wrapping them visually.

mongod --replSet m101 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork

mongod --replSet m101 --logpath "2.log" --dbpath /data/rs2 --port 27018 --smallfiles --oplogSize 64 --fork

mongod --replSet m101 --logpath "3.log" --dbpath /data/rs3 --port 27019 --smallfiles --oplogSize 64 --fork
Windows users: Omit -p from mkdir. Also omit --fork and use start mongod with Windows compatible paths (i.e. backslashes "\") for the --dbpath argument (e.g; C:\data\rs1).
Now connect to a mongo shell and make sure it comes up

Now you will create the replica set. Type the following commands into the mongo shell:

config = { _id: "m101", members:[
          { _id : 0, host : "localhost:27017"},
          { _id : 1, host : "localhost:27018"},
          { _id : 2, host : "localhost:27019"} ]
};
rs.initiate(config);
At this point, the replica set should be coming up. You can type

rs.status()
to see the state of replication.
Now run validate.py to confirm that it works.

python validate.py
Validate connects to your local replica set and checks that it has three nodes. It has been tested under Pymongo 2.3 and 2.4. Type the validation code below.

Solution :kjvjkl3290mf0m20f2kjjv


At the end I just want to say if you want to learn mongoDB, First practice with youself. because no one can steel talent 😇

WEEK 4 :PERFORMANCE : M101P: MONGODB FOR DEVELOPERS


Homework 4.1


Suppose you have a collection with the following indexes:

> db.products.getIndexes()
[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "ns" : "store.products",
        "name" : "_id_"
    },
    {
        "v" : 1,
        "key" : {
            "sku" : 1
        },
                "unique" : true,
        "ns" : "store.products",
        "name" : "sku_1"
    },
    {
        "v" : 1,
        "key" : {
            "price" : -1
        },
        "ns" : "store.products",
        "name" : "price_-1"
    },
    {
        "v" : 1,
        "key" : {
            "description" : 1
        },
        "ns" : "store.products",
        "name" : "description_1"
    },
    {
        "v" : 1,
        "key" : {
            "category" : 1,
            "brand" : 1
        },
        "ns" : "store.products",
        "name" : "category_1_brand_1"
    },
    {
        "v" : 1,
        "key" : {
            "reviews.author" : 1
        },
        "ns" : "store.products",
        "name" : "reviews.author_1"
    }
]
Which of the following queries can utilize at least one index to find all matching documents, or to sort? Check all that apply.

Note: the text for some answers may wrap; you can ignore the wrapping.

Solution : There are two possible answer as below 

Solutions for Homework 4.1-M101p Mongodb For Develoeprs,Answers for Homework 4.1-M101p Mongodb For Develoeprs,Anupam Singh Pal, ShyamSoftwares

Homework 4.2

Suppose you have a collection called tweets whose documents contain information about the created_at time of the tweet and the user's followers_count at the time they issued the tweet. What can you infer from the following explain output?
> db.tweets.explain("executionStats").find( { "user.followers_count" : { $gt : 1000 } } ).limit(10).skip(5000).sort( { created_at : 1 } )
{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "twitter.tweets",
        "indexFilterSet" : false,
        "parsedQuery" : {
            "user.followers_count" : {
                "$gt" : 1000
            }
        },
        "winningPlan" : {
            "stage" : "LIMIT",
            "limitAmount" : 0,
            "inputStage" : {
                "stage" : "SKIP",
                "skipAmount" : 0,
                "inputStage" : {
                    "stage" : "FETCH",
                    "filter" : {
                        "user.followers_count" : {
                            "$gt" : 1000
                        }
                    },
                    "inputStage" : {
                        "stage" : "IXSCAN",
                        "keyPattern" : {
                            "created_at" : -1
                        },
                        "indexName" : "created_at_-1",
                        "isMultiKey" : false,
                        "direction" : "backward",
                        "indexBounds" : {
                            "created_at" : [
                                "[MinKey, MaxKey]"
                            ]
                        }
                    }
                }
            }
        },
        "rejectedPlans" : [ ]
    },
    "executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 10,
        "executionTimeMillis" : 563,
        "totalKeysExamined" : 251120,
        "totalDocsExamined" : 251120,
        "executionStages" : {
            "stage" : "LIMIT",
            "nReturned" : 10,
            "executionTimeMillisEstimate" : 500,
            "works" : 251121,
            "advanced" : 10,
            "needTime" : 251110,
            "needFetch" : 0,
            "saveState" : 1961,
            "restoreState" : 1961,
            "isEOF" : 1,
            "invalidates" : 0,
            "limitAmount" : 0,
            "inputStage" : {
                "stage" : "SKIP",
                "nReturned" : 10,
                "executionTimeMillisEstimate" : 500,
                "works" : 251120,
                "advanced" : 10,
                "needTime" : 251110,
                "needFetch" : 0,
                "saveState" : 1961,
                "restoreState" : 1961,
                "isEOF" : 0,
                "invalidates" : 0,
                "skipAmount" : 0,
                "inputStage" : {
                    "stage" : "FETCH",
                    "filter" : {
                        "user.followers_count" : {
                            "$gt" : 1000
                        }
                    },
                    "nReturned" : 5010,
                    "executionTimeMillisEstimate" : 490,
                    "works" : 251120,
                    "advanced" : 5010,
                    "needTime" : 246110,
                    "needFetch" : 0,
                    "saveState" : 1961,
                    "restoreState" : 1961,
                    "isEOF" : 0,
                    "invalidates" : 0,
                    "docsExamined" : 251120,
                    "alreadyHasObj" : 0,
                    "inputStage" : {
                        "stage" : "IXSCAN",
                        "nReturned" : 251120,
                        "executionTimeMillisEstimate" : 100,
                        "works" : 251120,
                        "advanced" : 251120,
                        "needTime" : 0,
                        "needFetch" : 0,
                        "saveState" : 1961,
                        "restoreState" : 1961,
                        "isEOF" : 0,
                        "invalidates" : 0,
                        "keyPattern" : {
                            "created_at" : -1
                        },
                        "indexName" : "created_at_-1",
                        "isMultiKey" : false,
                        "direction" : "backward",
                        "indexBounds" : {
                            "created_at" : [
                                "[MinKey, MaxKey]"
                            ]
                        },
                        "keysExamined" : 251120,
                        "dupsTested" : 0,
                        "dupsDropped" : 0,
                        "seenInvalidated" : 0,
                        "matchTested" : 0
                    }
                }
            }
        }
    },
    "serverInfo" : {
        "host" : "generic-name.local",
        "port" : 27017,
        "version" : "3.0.1",
        "gitVersion" : "534b5a3f9d10f00cd27737fbcd951032248b5952"
    },
    "ok" : 1
}


Solution : There are two possible answer as below

Solutions for Homework 4.2-M101p Mongodb For Develoeprs,Answers for Homework 4.2-M101p Mongodb For Develoeprs, Anupam Singh Pal, Shyam Softwares


Homework 4.3


Making the Blog fast
Please download hw4-3.zip from the Download Handout link to get started. This assignment requires Mongo 3.0 or above.

In this homework assignment you will be adding some indexes to the post collection to make the blog fast.

We have provided the full code for the blog application and you don't need to make any changes, or even run the blog. But you can, for fun.

We are also providing a patriotic (if you are an American) data set for the blog. There are 1000 entries with lots of comments and tags. You must load this dataset to complete the problem.

From the mongo shell:

use blog
db.posts.drop()

From the mac or PC terminal window
mongoimport --drop -d blog -c posts posts.json
The blog has been enhanced so that it can also display the top 10 most recent posts by tag. There are hyperlinks from the post tags to the page that displays the 10 most recent blog entries for that tag. (run the blog and it will be obvious)

Your assignment is to make the following blog pages fast:

The blog home page
The page that displays blog posts by tag (http://localhost:8082/tag/whatever)
The page that displays a blog entry by permalink (http://localhost:8082/post/permalink)
By fast, we mean that indexes should be in place to satisfy these queries such that we only need to scan the number of documents we are going to return.

To figure out what queries you need to optimize, you can read the blog.py code and see what it does to display those pages. Isolate those queries and use explain to explore.

Once you have added the indexes to make those pages fast run the following
python validate.py
(note that for folks who are using MongoLabs or MongoHQ there are some command line options to validate.py to make it possible to use those services) Now enter the validation code below.

Solution : 893jfns29f728fn29f20f2

Solutions for Homework 4.3-M101p Mongodb For Develoeprs,Anupam Singh Pal, Shyam Softwares


Homework 4.4

In this problem you will analyze a profile log taken from a different mongoDB instance and you will import it into a collection named sysprofile. To start, please download sysprofile.json from Download Handout link and import it with the following command:
mongoimport --drop -d m101 -c profile sysprofile.json
Now query the profile data, looking for all queries to the students collection in the database school2, sorted in order of decreasing latency. What is the latency of the longest running operation to the collection, in milliseconds?

Solution : 15820


Solutions for Homework 4.4-M101p Mongodb For Develoeprs,Anupam Singh Pal, ShyamSoftwares
At the end I just want to say if you want to learn mongoDB, First practice with youself. because no one can steel talent 😇

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
db.students.count()
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' },
  {
    '$group':
    {
      '_id': '$_id',
      'average': { $avg: '$scores.score' }
    }
  },
  { '$sort': { 'average' : -1 } },
  { '$limit': 1 } ] )



Solution : 13


Homework 3.1 week-3 Mongodb For Developers,m101p,Anupam Singh Pal, Shyam Softwares

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

http://localhost:8082/
http://localhost:8082/signup
http://localhost:8082/login
http://localhost:8082/newpost
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,Anupam Singh Pal, Shyam Softwares

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" : [
        "cycling",
        "running",
        "swimming"
    ],
    "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,Anupam SIngh Pal, ShyamSoftwares

At the end I just want to say if you want to learn mongoDB, First practice with youself. because no one can steel talent 😇

Week 2 : CRUD: M101P: MONGODB FOR DEVELOPERS 2017

Homework 2.1


IN THIS PROBLEM, YOU WILL BE USING A COLLECTION OF STUDENT SCORES THAT IS SIMILAR TO WHAT WE USED IN THE LESSONS. PLEASE DOWNLOAD GRADES.JSON FROM THE DOWNLOAD HANDOUT LINK AND IMPORT IT INTO YOUR LOCAL MONGO DATABASE AS FOLLOWS:

MONGOIMPORT --DROP -D STUDENTS -C GRADES GRADES.JSON

The dataset contains 4 scores for 200 students.
First, let's confirm your data is intact; the number of documents should be 800.

use students
db.grades.count()
You should get 800.

This next query, which uses the aggregation framework that we have not taught yet, will tell you the student_id with the highest average score:

db.grades.aggregate({'$group':{'_id':'$student_id', 'average':{$avg:'$score'}}}, {'$sort':{'average':-1}}, {'$limit':1})
The answer should be student_id 164 with an average of approximately 89.3.

Now it's your turn to analyze the data set. Find all exam scores greater than or equal to 65, and sort those scores from lowest to highest.

What is the student_id of the lowest exam score above 65?

Solution :

    Query : db.grades.find( { score : { $gte : 65 } } ).sort( { score : 1 } )

    Answer : 22

2.1_MongoDB_for_Developer,Anupam,Shyam Softwares

Homework 2.2


WRITE A PROGRAM IN THE LANGUAGE OF YOUR CHOICE THAT WILL REMOVE THE GRADE OF TYPE "HOMEWORK" WITH THE LOWEST SCORE FOR EACH STUDENT FROM THE DATASET IN THE HANDOUT. SINCE EACH DOCUMENT IS ONE GRADE, IT SHOULD REMOVE ONE DOCUMENT PER STUDENT. THIS WILL USE THE SAME DATA SET AS THE LAST PROBLEM, BUT IF YOU DON'T HAVE IT, YOU CAN DOWNLOAD AND RE-IMPORT.

THE DATASET CONTAINS 4 SCORES EACH FOR 200 STUDENTS.

FIRST, LET'S CONFIRM YOUR DATA IS INTACT; THE NUMBER OF DOCUMENTS SHOULD BE 800.

use students
db.grades.count()

Hint/spoiler: If you select homework grade-documents, sort by student and then by score, you can iterate through and find the lowest score for each student by noticing a change in student id. As you notice that change of student_id, remove the document.

To confirm you are on the right track, here are some queries to run after you process the data and put it into the grades collection:

Let us count the number of grades we have:


db.grades.count()
The result should be 600. Now let us find the student who holds the 101st best grade across all grades:

db.grades.find().sort( { 'score' : -1 } ).skip( 100 ).limit( 1 )
The correct result will be:

{ "_id" : ObjectId("50906d7fa3c412bb040eb709"), "student_id" : 100, "type" : "homework", "score" : 88.50425479139126 }

Now let us sort the students by student_id , and score, while also displaying the type to then see what the top five docs are:

db.grades.find( { }, { 'student_id' : 1, 'type' : 1, 'score' : 1, '_id' : 0 } ).sort( { 'student_id' : 1, 'score' : 1, } ).limit( 5 )
The result set should be:

{ "student_id" : 0, "type" : "quiz", "score" : 31.95004496742112 }
{ "student_id" : 0, "type" : "exam", "score" : 54.6535436362647 }
{ "student_id" : 0, "type" : "homework", "score" : 63.98402553675503 }
{ "student_id" : 1, "type" : "homework", "score" : 44.31667452616328 }
{ "student_id" : 1, "type" : "exam", "score" : 74.20010837299897 }

To verify that you have completed this task correctly, provide the identity 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.grades.aggregate( { '$group' : { '_id' : '$student_id', 'average' : { $avg : '$score' } } }, { '$sort' : { 'average' : -1 } }, { '$limit' : 1 } )

Enter the student ID below. Please enter just the number, with no spaces, commas or other characters.

 Answer : 54

2.2_MongoDB_for_Developer,Anupam,Future is here

Homework 2.3

BLOG USER SIGN-UP AND LOGIN

DOWNLOAD THE HANDOUT AND UNPACK IT.

YOU SHOULD SEE THREE FILES AT THE HIGHEST LEVEL: BLOG.PY, USERDAO.PY AND SESSIONDAO.PY. THERE IS ALSO A VIEWS DIRECTORY WHICH CONTAINS THE TEMPLATES FOR THE PROJECT.

THE PROJECT ROUGHLY FOLLOWS THE MODEL/VIEW/CONTROLLER PARADIGM. USERDAO AND SESSIONDAO.PY COMPRISE THE MODEL. BLOG.PY IS THE CONTROLLER. THE TEMPLATES COMPRISE THE VIEW.

IF EVERYTHING IS WORKING PROPERLY, YOU SHOULD BE ABLE TO START THE BLOG BY TYPING:

python blog.py

Note that this project requires the following python modules be installed on your computer: cgi, hmac, datetime, json, sys, string, hashlib, urllib, urllib2, random, re, pymongo, and bottle. If you have python installed at all, you probably already have most of these installed except pymongo and bottle.

If you have python-setuptools installed, the command "pip" makes this simple. Any other missing packages will show up when validate.py is run, and can be installed in a similar fashion. As of this recording, we are still using the beta version of PyMongo so we will install directly from GitHub. Note that this directions are identical to what we taught you within the lessons and you should already have PyMongo 3.x and bottle installed. If not, use the following commands.

First, let's confirm your data is intact; the number of documents should be 800.

$ pip install https://github.com/mongodb/mongo-python-driver/archive/3.0b1.tar.gz
$ pip install bottle
If you go to http://localhost:8082 you should see a message, "this is a placeholder for the blog"

Here are some URLs that must work when you are done.



http://localhost:8082/signup
http://localhost:8082/login
http://localhost:8082/logout

This next query, which uses the aggregation framework that we have not taught yet, will tell you the student_id with the highest average score:

Solution :  jkfds5834j98fnm39njf0920f02

2.3_MongoDB_for_Developer,Anupam


HOMEWORK 2.4 :

WHICH OF THE CHOICES BELOW IS THE TITLE OF A MOVIE FROM THE YEAR 2013 THAT IS RATED PG-13 AND WON NO AWARDS? PLEASE QUERY THE VIDEO.MOVIEDETAILS COLLECTION TO FIND THE ANSWER.

NOTE: THERE IS A DUMP OF THE VIDEO DATABASE INCLUDED IN THE HANDOUTS FOR THE "CREATING DOCUMENTS" LESSON. USE THAT DATA SET TO ANSWER THIS QUESTION.


2.4_MongoDB_for_Developer,Anupam,Latest Technological Blog


Homework 2.5

USING THE VIDEO.MOVIEDETAILS COLLECTION, HOW MANY MOVIES LIST "SWEDEN" SECOND IN THE THE LIST OF COUNTRIES.

NOTE: THERE IS A DUMP OF THE VIDEO DATABASE INCLUDED IN THE HANDOUTS FOR THE "CREATING DOCUMENTS" LESSON. USE THAT DATA SET TO ANSWER THIS QUESTION.


2.5_MongoDB_for_Developer,Anupam,Future is here


Friday, 8 September 2017

Week 1 : INTRODUCTION : M101P: MongoDB For Developers


Homework 1.1


Install MongoDB on your computer and run it on the standard port.
Download the HW1-1 from the Download Handout link and uncompress it.
Use mongorestore to restore the dump into your running mongod. Do this by opening a terminal window (mac) or cmd window (windows) and navigating to the directory so that you are in the parent directory of the dump directory (if you used the default extraction method, it should be hw1/). Now type:

mongorestore dump

Note you will need to have your path setup correctly to find mongorestore.

Next, go into the Mongo shell, perform a findOne on the collection called hw1 in the database m101. That will return one document. Please provide the value corresponding to the "answer" key from the document returned.

hint: if you got back a document that looks like { "_id": 1234, "answer": 2468 }, you would put in 2468 (with no spaces) for your answer. This is not the correct number; you should get a different number. 

Answer :  42

Homework 1.1 : Introduction : M101P: MongoDB for Developers,Anupam


Homework 1.2 : 

Get PyMongo installed on your computer. To prove its installed, run the program:

python hw1-2.py
Note that you will need to get MongoDB installed and the homework dataset imported from the previous homework before attempting this problem.

This program will print a numeric answer. Please put just the 4-digit number into the box below (no spaces).

Answer : 1815

Homework 1.2 : Introduction : M101P: MongoDB for Developers,Anupam Singh pal,mongodb m101p solutions


Homework 1.3


We are now going to test that you have bottle installed correctly and can run a bottle-based project. Download the handout and run it as follows:

python hw1-3.py

It requires that:

bottle be installed correctly
your mongodb to be running
you have run mongorestore properly

From a different terminal window type the following from the command line: curl

http://localhost:8080/hw1/50

Alternatively, you can put the url above into your web browser.

Type the two-digit answer into the box below (no spaces).

Answer : 53


Homework 1.3 : Introduction : M101P: MongoDB for Developers, Anupam Singh Pal, mongodb m101p solutions


At the end I just want to say if you want to learn mongoDB, First practice with youself. because no one can steel talent 😇