Created
February 7, 2015 00:06
-
-
Save SkylerRogers/a1642f7e0dc8dfde60c9 to your computer and use it in GitHub Desktop.
Delete Undefined Mongoid Indexes for Given Model
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
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