Module: Mongoid::Indexes::ClassMethods

Defined in:
lib/mongoid/indexes.rb

Overview

:nodoc

Instance Method Summary collapse

Instance Method Details

#add_indexesObject

Add the default indexes to the root document if they do not already exist. Currently this is only _type.



16
17
18
19
20
21
# File 'lib/mongoid/indexes.rb', line 16

def add_indexes
  if hereditary && !indexed
    self._collection.create_index(:_type, :unique => false, :background => true)
    self.indexed = true
  end
end

#index(name, options = { :unique => false }) ⇒ Object

Adds an index on the field specified. Options can be :unique => true or :unique => false. It will default to the latter.



25
26
27
# File 'lib/mongoid/indexes.rb', line 25

def index(name, options = { :unique => false })
  collection.create_index(name, options)
end