Skip to content

Instantly share code, notes, and snippets.

@dandrews
Forked from fabioyamate/model.rb
Created August 5, 2014 20:57
Show Gist options
  • Save dandrews/f80914ff535f1c6ac3cd to your computer and use it in GitHub Desktop.
Save dandrews/f80914ff535f1c6ac3cd to your computer and use it in GitHub Desktop.
# 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