Skip to content

Instantly share code, notes, and snippets.

@SkylerRogers
Created February 7, 2015 00:06
Show Gist options
  • Save SkylerRogers/a1642f7e0dc8dfde60c9 to your computer and use it in GitHub Desktop.
Save SkylerRogers/a1642f7e0dc8dfde60c9 to your computer and use it in GitHub Desktop.
Delete Undefined Mongoid Indexes for Given Model
model = YourModel
current_index_keys = model.collection.indexes.entries.map{|x| x['key'].stringify_keys unless x['key'] == {"_id"=>1}}.compact
defined_index_keys = model.index_options.keys.map{|x| x.stringify_keys}
current_index_keys.each do |k|
model.collection.indexes.drop(k) unless defined_index_keys.include?(k)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment