Mongodb Homework 1.4


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

Write a program in the language of your choice that will remove the grade of type "homework" with the lowest score for each studentfrom the dataset (/static/m101j-october-2013/handouts/grades.839101a18c6f.json) that you imported in HW 2.1. Since eachdocument is one grade, it should remove one document per student.


: If you select homework grade-documents, sort by student and then by score, you can iterate through and find the lowestscore 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, her eare some queries to run after you process the data with the correct answer shown:Let us count the number of grades we have:

> db.grades.count()600

Now let us find thestudent who holds the 101st best grade across all grades:

> db.grades.find().sort({'score':-1}).skip(100).limit(1){ "_id" : ObjectId("513257f68d6e7cb63d7b1ead"), "student_id" : 164, "type" : "exam", "score" :87.06518186605459 }

Now let us sort the students by student_id, score and 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){ "student_id" : 0, "type" : "quiz", "score" : 16.28337833467709 }{ "student_id" : 0, "type" : "exam", "score" : 64.40706888325151 }{ "student_id" : 0, "type" : "homework", "score" : 80.31845193864314 }{ "student_id" : 1, "type" : "quiz", "score" : 11.45004974085635 }{ "student_id" : 1, "type" : "homework", "score" : 31.56114538077717 }

To verify that you have completed this task correctly, provide the identify of the student with the highest average in the class withfollowing 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.


Courses (/courses)Help (/help) About (/about)Blog ( (/DASHBOARD)




 As a reminder, to run your blog you type

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

Or, use an IDE to run it. 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:


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

Read if you want to run your blog on non-standard port, different host or connected to a mongod on different server.

By popular demand, now takes some optional arguments that you can discover with the -h flag. These arguments will allow you to to make a connection to a web server at different port on a different host and connect to a mongod on a different host. You can also use adatabase name other than blog, a necessity if you are running on the free tier at MongoHW (for eg). I won't go into how these arguments work, as they arepretty self documenting. Note that to run the code to connect to a database outside of localhost (for example to a database at MongoHQ), you willneed to make some global changes.

The python validator requires Python 2.7. The code is not 3.0 compliant.Ok, once you get the blog posts working, will print out a validation code for HW 3.2. Please enter it below, exactly asshown with no spaces.njkfd489hj9fhds8934kf23


You have used 0 of 3 submissions


0 Thoughts to “Mongodb Homework 1.4

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *