Skip to content

Instantly share code, notes, and snippets.

@geeky-sh
Forked from dira/rename_mongoid_collection.rb
Created December 19, 2013 07:09
Show Gist options
  • Save geeky-sh/8035481 to your computer and use it in GitHub Desktop.
Save geeky-sh/8035481 to your computer and use it in GitHub Desktop.
# want to nest `Video` under `Media`; had a `videos` collection
# rename the collection:
Mongoid.database.drop_collection('videos')
Mongoid.database.rename_collection('videos', 'media')
# or
Mongoid.database.collection('videos').rename('media')
# change the type of all the existing records
Media.update_all(_type: 'Video')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment