Created
March 22, 2018 19:45
-
-
Save adamrunner/0214876f6afd1bdf9398589eb16947f5 to your computer and use it in GitHub Desktop.
Revisions
-
adamrunner created this gist
Mar 22, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ class Mongoid::Migration # renames a collection in mongodb, can be told to drop the target collection first def self.rename_collection(old_name, new_name, drop_target=false) client = Mongoid::Clients.default current_db = client.database admin_db = Mongo::Database.new(client, Mongo::Database::ADMIN, current_db.options) admin_db.command(renameCollection: "#{current_db.name}.#{old_name}", to: "#{current_db.name}.#{new_name}", dropTarget: drop_target) end end