Method: Rails::Mongoid#remove_indexes

Defined in:
lib/rails/mongoid.rb

#remove_indexes(*globs) ⇒ Array<Class>

Remove indexes for each model given the provided globs and the class is not embedded.

Examples:

Remove all the indexes.

Rails::Mongoid.create_indexes("app/models/**/*.rb")

Parameters:

  • globs (Array<String>)

    The file matching globs.

Returns:

  • (Array<Class>)

    The un-indexed models.



44
45
46
47
48
49
50
51
52
53
# File 'lib/rails/mongoid.rb', line 44

def remove_indexes(*globs)
  models(*globs).each do |model|
    next if model.embedded?
    indexes = model.collection.indexes.map{ |doc| doc["name"] }
    indexes.delete_one("_id_")
    model.remove_indexes
    logger.info("MONGOID: Removing indexes on: #{model} for: #{indexes.join(', ')}.")
    model
  end.compact
end