Navigation
This version of the documentation is archived and no longer supported.

db.collection.createIndex()

db.collection.createIndex(keys, options)
Parameters:
  • keys (document) – A document that contains pairs with the name of the field or fields to index and order of the index. A 1 specifies ascending and a -1 specifies descending.
  • options (document) – A document that controls the creation of the index. This argument is optional.

The ensureIndex() method is the preferred way to create indexes on collections.