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 63 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| if database = options[:database] with(consistency: :strong, database: database). collection.indexes.create(spec, options.except(:database)) else with(consistency: :strong).collection.indexes.create(spec, options) end 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 87 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 43 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
Generated with the Darkfish Rdoc Generator 2.