Skip to content

Instantly share code, notes, and snippets.

@GusGA
Created December 12, 2013 01:20
Show Gist options
  • Save GusGA/7921722 to your computer and use it in GitHub Desktop.
Save GusGA/7921722 to your computer and use it in GitHub Desktop.
Script para eliminar el la la nota de la tarea con menor nota / Script to eliminate the homework with less score
require 'mongo'
@client = Mongo::Connection.new('localhost',27017)
@db = @client['school']
@collection = @db['students']
@filter = Array.new
@collection.find().each do |student|
hash = Hash.new
puts student['_id']
hash['id'] = student['_id']
hash['scores'] = []
student['scores'].each { |score| hash['scores'] << score['score'] if score['type'] == 'homework' }
@filter << hash
end
@filter.each do |hash|
@collection.update(
{'_id' => hash['id']},
{'$pull' => {'scores' => {'type' => 'homework', 'score' => hash['scores'].sort[0]}}}
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment