Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Playing around with removing mongo indexes in standard active record migrations.

View 000_remove_index_from_mongo_collection.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
class RemoveIndexFromMongoCollection < ActiveRecord::Migration
def self.up
remove_mongo_index 'my_collection', 'my_index'
end
 
def self.down
# Intentionally blank
end
private
def self.remove_mongo_index(collection, name, raise_on_missing_indexes=false)
begin
Mongoid.database.collection(collection).drop_index(name)
rescue Mongo::MongoDBError => e
if e.message =~ /index not found/
message = "Couldn't find the '#{name}' index in the '#{collection}' collection."
raise_on_missing_indexes ? raise("ERROR: #{message}") : puts("WARNING: #{message}")
else
raise e
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.