Module: Mongoid::Indexes::ClassMethods
- Defined in:
- lib/mongoid/indexes.rb
Instance Method Summary collapse
-
#add_indexes ⇒ true
Add the default indexes to the root document if they do not already exist.
-
#create_indexes ⇒ true
Send the actual index creation comments to the MongoDB driver.
-
#index(spec, options = nil) ⇒ Hash
index({ name: 1 }, { background: true }) end.
-
#remove_indexes ⇒ true
Send the actual index removal comments to the MongoDB driver, but lets _id untouched.
Instance Method Details
#add_indexes ⇒ true
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 }, { unique: false, background: true }) end true end |
#create_indexes ⇒ true
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 |
#index(spec, options = nil) ⇒ Hash
index({ name: 1 }, { background: true })
end
79 80 81 82 |
# File 'lib/mongoid/indexes.rb', line 79 def index(spec, = nil) Validators::Options.validate(self, spec, || {}) [spec] = () end |
#remove_indexes ⇒ true
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 |