Created
February 26, 2013 20:36
-
-
Save fabioyamate/5041934 to your computer and use it in GitHub Desktop.
MongoDB Moped rename collection
This file contains 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
# Since Mongoid switched to its own driver, many of the mongo API | |
# (available in mongo-ruby-drive) are missing. This is allows you | |
# to rename a collection thru command message. | |
# | |
# Be aware that the API constantly changes in mongoid | |
# | |
# Mongoid (3.1.0), Moped (1.4.2) | |
class MyModel | |
include Mongoid::Document | |
def self.rename(to, dropTarget = false) | |
database = collection.database | |
database.session.with(:database => "admin", :consistency => :strong) do |session| | |
session.command({ :renameCollection => "#{database.name}.#{collection_name}", :to => "#{database.name}.#{to}", :dropTarget => dropTarget }) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment