Add the default indexes to the root document if they do not already exist. Currently this is only _type.
@example Add Mongoid internal indexes.
Person.add_indexes
@return [ true ] If the operation succeeded.
@since 1.0.0
# File lib/mongoid/indexes.rb, line 54 def add_indexes if hereditary? && !index_options[{ _type: 1 }] index({ _type: 1 }, { unique: false, background: true }) end true end
Send the actual index creation comments to the MongoDB driver
@example Create the indexes for the class.
Person.create_indexes
@return [ true ] If the operation succeeded.
@since 1.0.0
# File lib/mongoid/indexes.rb, line 22 def create_indexes return unless index_options index_options.each_pair do |spec, options| collection.indexes.create(spec, options) end and true end
index({ name: 1 }, { background: true })
end
@param [ Symbol ] name The name of the field. @param [ Hash ] options The index options.
@return [ Hash ] The index options.
@since 1.0.0
# File lib/mongoid/indexes.rb, line 78 def index(spec, options = nil) Validators::Options.validate(self, spec, options || {}) index_options[normalize_spec(spec)] = normalize_index_options(options) end
Send the actual index removal comments to the MongoDB driver, but lets _id untouched.
@example Remove the indexes for the class.
Person.remove_indexes
@return [ true ] If the operation succeeded.
@since 3.0.0
# File lib/mongoid/indexes.rb, line 38 def remove_indexes with(consistency: :strong).collection.indexes.each do |spec| next if spec["name"] == "_id_" collection.indexes.drop(spec["key"]) end and true end
Generated with the Darkfish Rdoc Generator 2.