M101j Homework 1.1

On By In 1

Courseware (/courses/10gen/M101J/2013_October/courseware) Course Info (/courses/10gen/M101J/2013_October/info)Discussion (/courses/10gen/M101J/2013_October/discussion/forum) Wiki (/courses/10gen/M101J/2013_October/course_wiki)Progress (/courses/10gen/M101J/2013_October/progress)


M101J: MongoDB for Java Developers

Homework: Homework 2.3

Blog User Sign-up and Login

Download hw2.3.zip (/static/m101j-october-2013/handouts/hw2-3.7f0c86868288.zip) or hw2.3.tar (/static/m101j-october-2013/handouts/hw2-3.a7c14526bec0.tar) and unpack. This is the beginning of the blog project with the UI for creating an logging inblog authors, but nothing to display posts.There is a pom.xml file that describes the project.The project roughly follows the model/view/controller paradigm.

BlogControll er.java

is the controller and the model. The templatescomprise the view. Here is a description of the directories and files.

/src/main/java/course - contains source code/src/main/resources/freemarker - contains templatesvalidate.py - the python script that will validate you got it rightrun.sh - the mvn command that starts it running if you don't want to use an IDE

If everything is working properly, you should be able to start the blog by typing:

mvn compile exec:java -Dexec.mainClass=course.BlogController

If you goto http://localhost:8082 (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.


When you login or sign-up, the blog will redirect to http://localhost:8082/welcome and that must work properly, welcoming the user byusernameWe have removed four Java statements from UserDAO and marked the areas where you need to work with XXX. You should notneed to touch any other code. The java statements that you are going to add will add a new user upon sign-up and validate a login byretrieving the right user document.The blog stores its data in the blog database in two collections,




. Here are two example docs for a username‘erlichson’ with password ‘fubar’. You can insert these if you like, but you don’t need to.

> db.users.find(){ "_id" : "erlichson", "password" : "VH9IFu+/vUNSKTzZsFZEOsK1,-1924261330" }>


Courses (/courses)Help (/help) About (/about)Blog (http://ed-blog.mongodb.com/)DMAKETAS (/DASHBOARD)


Courseware (/courses/10gen/M101J/2013_October/courseware) Course Info (/courses/10gen/M101J/2013_October/info)Discussion (/courses/10gen/M101J/2013_October/discussion/forum) Wiki (/courses/10gen/M101J/2013_October/course_wiki)Progress (/courses/10gen/M101J/2013_October/progress)


M101J: MongoDB for Java Developers

Homework: HW 3.1

Download the students.json (/static/m101j-october-2013/handouts/students.432aefc2cf4e.json) file to your computer and import itinto your local Mongo instance with this command:

$ mongoimport -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 byinspecting it in the Mongo shell.Write a program in Java that will remove the lowest homework score for each student. Since there is a single document for eachstudent containing an array of scores, you will need to update the scores array and remove the homework.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 incode and then update the scores array with the low homework pruned. If you are struggling with the Java side of this, look at the ArrayList.remove method, which can remove stuff from a Java ArrayList. Note also that when the value for a particular key is list withinMongoDB, the Java driver returns a BasicDBList, which can you cast to an ArrayList.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()200

Let's see what Demarcus Audette's record looks like:

>db.students.find({_id:100}).pretty(){"_id" : 100,"name" : "Demarcus Audette","scores" : [{"type" : "exam","score" : 30.61740640636871},{"" ""


Courses (/courses)Help (/help) About (/about)Blog (http://ed-blog.mongodb.com/)DMAKETAS (/DASHBOARD)


Leave a Reply

Your email address will not be published. Required fields are marked *