Module: Mongoid::Indexes::ClassMethods
- Defined in:
- lib/mongoid/indexes.rb
Instance Method Summary (collapse)
-
- (true) add_indexes
Add the default indexes to the root document if they do not already exist.
-
- (true) create_indexes
Send the actual index creation comments to the MongoDB driver.
-
- (Hash) index(spec)
Adds an index on the field specified.
-
- (true) remove_indexes
Send the actual index removal comments to the MongoDB driver, but lets _id untouched.
Instance Method Details
- (true) add_indexes
Add the default indexes to the root document if they do not already exist. Currently this is only _type.
55 56 57 58 59 60 |
# File 'lib/mongoid/indexes.rb', line 55 def add_indexes if hereditary? && ![{ _type: 1 }] index _type: 1, options: { unique: false, background: true } end true end |
- (true) create_indexes
Send the actual index creation comments to the MongoDB driver
23 24 25 26 27 28 |
# File 'lib/mongoid/indexes.rb', line 23 def create_indexes return unless .each_pair do |spec, | collection.indexes.create(spec, ) end and true end |
- (Hash) index(spec)
Adds an index on the field specified. Options can be :unique => true or :unique => false. It will default to the latter.
78 79 80 81 |
# File 'lib/mongoid/indexes.rb', line 78 def index(spec) Validators::Options.validate(self, spec) [spec] = (spec) end |
- (true) remove_indexes
Send the actual index removal comments to the MongoDB driver, but lets _id untouched.
39 40 41 42 43 44 |
# File 'lib/mongoid/indexes.rb', line 39 def remove_indexes collection.indexes.each do |spec| next if spec["name"] == "_id_" collection.indexes.drop(spec["key"]) end and true end |