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.
-
#create_indexes ⇒ Object
Send the actual index creation comments to the MongoDB driver.
-
#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.
30 31 32 33 34 35 |
# File 'lib/mongoid/indexes.rb', line 30 def add_indexes if hereditary? && ![:_type] self.[:_type] = {:unique => false, :background => true} end create_indexes if Mongoid.autocreate_indexes end |
#create_indexes ⇒ Object
Send the actual index creation comments to the MongoDB driver
17 18 19 20 21 22 23 |
# File 'lib/mongoid/indexes.rb', line 17 def create_indexes return unless current_collection = self._collection || set_collection .each_pair do |name, | current_collection.create_index(name, ) 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.
48 49 50 51 |
# File 'lib/mongoid/indexes.rb', line 48 def index(name, = { :unique => false }) self.[name] = create_indexes if Mongoid.autocreate_indexes end |