Skip to content

Instantly share code, notes, and snippets.

@thinkclay
Created April 22, 2013 08:18
Show Gist options
  • Save thinkclay/5433225 to your computer and use it in GitHub Desktop.
Save thinkclay/5433225 to your computer and use it in GitHub Desktop.
MongoDB M101 HW 3.1 in Ruby
require 'mongo'
require 'json'
include Mongo
@client = MongoClient.new('localhost', 27017)
@db = @client['school']
@students = @db['students']
@students.find().each { |student|
@filter = [];
puts student['_id']
student['scores'].each { |score|
if score['type'] == 'homework'
@filter << score['score']
end
}
@students.update(
{
'_id' => student['_id'],
},
{
'$pull' => {'scores' => { 'type' => 'homework', 'score' => @filter.sort[0] } }
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment