Module: Mongoid::Indexes::ClassMethods
- Defined in:
- lib/mongoid/indexes.rb
Overview
:nodoc
Instance Method Summary collapse
-
#add_indexes ⇒ Object
Add the default indexes to the root document if they do not already exist.
-
#index(name, options = { :unique => false }) ⇒ Object
Adds an index on the field specified.
Instance Method Details
#add_indexes ⇒ Object
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, = { :unique => false }) collection.create_index(name, ) end |