Skip to content

Instantly share code, notes, and snippets.

@exAspArk
Last active October 4, 2019 21:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save exAspArk/36771c7b1a6d416eb9a25007f4ab1772 to your computer and use it in GitHub Desktop.
Save exAspArk/36771c7b1a6d416eb9a25007f4ab1772 to your computer and use it in GitHub Desktop.
defined_indexes = Model.index_specifications.map { |s| s.fields.map(&:to_s) };
existing_indexes = Model.collection.indexes.map { |i| i['key'].keys };
missing_indexes = defined_indexes - existing_indexes
# => []
extra_indexes = existing_indexes - defined_indexes - [['_id']]
# => []
#################################################################################
# if the arrays are correct (hopefully the indexes have {background: true} flag),
# then you're good to run
Model.create_indexes # or Model.remove_indexes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment