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.
64 65 66 67 68 69 |
# File 'lib/mongoid/indexes.rb', line 64 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 29 30 31 32 33 |
# File 'lib/mongoid/indexes.rb', line 23 def create_indexes return unless .each_pair do |spec, | if database = [:database] with(consistency: :strong, database: database). collection.indexes.create(spec, .except(:database)) else with(consistency: :strong).collection.indexes.create(spec, ) end end and true end |
#index(spec, options = nil) ⇒ Hash
index({ name: 1 }, { background: true })
end
88 89 90 91 |
# File 'lib/mongoid/indexes.rb', line 88 def index(spec, = nil) Validators::Options.validate(self, spec, || {}) [normalize_spec(spec)] = () end |
#remove_indexes ⇒ true
Send the actual index removal comments to the MongoDB driver, but lets _id untouched.
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mongoid/indexes.rb', line 44 def remove_indexes indexed_database_names.each do |database| collection = with(consistency: :strong, database: database).collection collection.indexes.each do |spec| unless spec["name"] == "_id_" collection.indexes.drop(spec["key"]) end end end and true end |