Created
February 1, 2012 04:11
-
-
Save ahoward/1715041 to your computer and use it in GitHub Desktop.
removing a bunch of mongo attributes in one hit #L19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddPageFields < Mongoid::Migration | |
def self.up | |
Account.all.each do |account| | |
account.pages.each do |page| | |
page.update_attributes!( | |
:callout => Account::Page::Defaults.callout, | |
:phone => Account::Page::Defaults.phone, | |
:email => Account::Page::Defaults.email | |
) | |
end | |
end | |
end | |
def self.down | |
query = {} | |
update = {'$unset' => {'pages.email' => true, 'pages.phone' => true, 'pages.callout' => true}} | |
opts = {'safe' => true} | |
Account.collection.update(query, update, opts) ### <- RAWK | |
end | |
end |
;-) i've made mistakes with $set/$unset methodologies in the past when i wanted to query like : '$exists' => {:root => true} because $exists is always a table scan. in this case, of course, we're just rolling back a schema modification, but i thought i'd mention is since '$unset' often is paired with '$exists' in code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I never liked attributes to begin with ;)