MongoDB Documentation, Release 3.0.4 The value of the field in the index specification describes the kind of index for that field. For example, a value of 1 specifies an index that orders items in ascending order. A value of -1 specifies an index that orders items in descending order. For additional index types, see Index Types (page 486). The following operation will create an index on the item , category , and price fields of the products collec- tion: If your collection holds a large amount of data, and your application needs to be able to access the data while building the index, consider building the index in the background, as described in Background Construction (page 508). To build indexes on replica sets, see the Build Indexes on Replica Sets (page 521) section for more information. Note: To build or rebuild indexes for a replica set see Build Indexes on Replica Sets (page 521). Some drivers may specify indexes, using NumberLong(1) rather than 1 as the specification. This does not have any affect on the resulting index. Create an Index (page 517), Indexing Tutorials (page 517) and Index Concepts (page 486) for more information. MongoDB allows you to specify a unique constraint (page 504) on an index. These constraints prevent applications from inserting documents that have duplicate values for the inserted fields. MongoDB cannot create a unique index (page 504) on the specified index field(s) if the collection already contains data that would violate the unique constraint for the index. To create a unique index (page 504), consider the following prototype: For example, you may want to create a unique index on the "tax-id" field of the accounts collection to prevent storing multiple account records for the same legal entity: The _id index (page 487) is a unique index. In some situations you may consider using the _id field itself for this kind of data rather than using a unique index on another field. 519 8.3. Indexing Tutorials db.collection.createIndex( { a: 1, b: 1, c: 1 } ) db.products.createIndex( { item: 1, category: 1, price: 1 } ) db.collection.createIndex( { a: 1 }, { unique: true } ) db.accounts.createIndex( { "tax-id": 1 }, { unique: true } ) Unique Index on a Single Field Create a Unique Index See also: Example Additional Considerations