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.
23 24 25 26 27 28 |
# File 'lib/mongoid/indexes.rb', line 23 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
13 14 15 16 17 18 19 |
# File 'lib/mongoid/indexes.rb', line 13 def create_indexes return unless current_collection = self._collection || set_collection .each 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.
32 33 34 35 |
# File 'lib/mongoid/indexes.rb', line 32 def index(name, = { :unique => false }) self.[name] = create_indexes if Mongoid.autocreate_indexes end |