Method: MongoDoc::Index#index
- Defined in:
- lib/mongo_doc/index.rb
#index(*args) ⇒ Object
Create an index on a collection.
For compound indexes, pass pairs of fields and directions (:asc, :desc) as a hash.
For a unique index, pass the option :unique => true. To create the index in the background, pass the options :background => true. If you want to remove duplicates from existing records when creating the unique index, pass the option :dropDups => true
For GeoIndexing, specify the minimum and maximum longitude and latitude values with the :min and :max options.
Person.index(:last_name) Person.index(:ssn, :unique => true) Person.index(:first_name => :asc, :last_name => :asc) Person.index(:first_name => :asc, :last_name => :asc, :unique => true)
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongo_doc/index.rb', line 26 def index(*args) = args. if args.any? collection.create_index(args.first, ) else fields = .except(*OPTIONS) = .slice(*OPTIONS) collection.create_index(to_mongo_direction(fields), ) end end |