Skip to content

Instantly share code, notes, and snippets.

@jnunemaker
Created December 18, 2009 19:49
Show Gist options
  • Save jnunemaker/259717 to your computer and use it in GitHub Desktop.
Save jnunemaker/259717 to your computer and use it in GitHub Desktop.
Simple example of how to remove a key from a mongo document
namespace :harmony do
desc "Munges the data"
task :munge => :environment do
docs_with_publish = Item.collection.find({'publish' => {'$exists' => true}}).to_a
puts "Item count: #{Item.count}"
puts "Items with publish key: #{docs_with_publish.size}"
docs_with_publish.each do |hash|
hash.delete('publish')
Item.collection.save(hash)
end
activities_with_thumbnail = Activity.collection.find({'source.thumbnail' => {'$exists' => true}}).to_a
puts "Activity count: #{Activity.count}"
puts "Activites with thumbnail: #{activities_with_thumbnail.size}"
activities_with_thumbnail.each do |hash|
hash['source'].delete('thumbnail')
Activity.collection.save(hash)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment