Created
March 17, 2017 09:40
-
-
Save Unnumbered/2feac77bba9fd87a9b417021e6deb76e to your computer and use it in GitHub Desktop.
how to rename mongodb collection with mongoid 5.x
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
def 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment