Skip to content

Instantly share code, notes, and snippets.

@mrmarcondes
Last active October 12, 2015 11:08
Show Gist options
  • Save mrmarcondes/4017296 to your computer and use it in GitHub Desktop.
Save mrmarcondes/4017296 to your computer and use it in GitHub Desktop.
10gen: M101 MongoDB for Developers - Homework 2.2
#ruby
client = Mongo::Client.new([ '127.0.0.1:27017' ], :database => 'm101')
grades = client[:grades].find("type" => "homework").sort({student_id:1, score:1})
student_id = nil
grades.each do |grade|
if student_id != grade["student_id"]
student_id = grade["student_id"]
client[:grades].find(_id: grade[:_id]).delete_one
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment