MongoDB Documentation, Release 3.0.4 Create an Index on a Single Field Additional Considerations See also: Create a Compound Index Build a Compound Index $^{7}$https://api.mongodb.org/ Chapter 8. Indexes 518 To create a compound index (page 489) use an operation that resembles the following prototype: Indexes allow MongoDB to process and fulfill queries quickly by creating small and efficient representations of the documents in a collection . MongoDB supports indexes that include content on a single field, as well as compound indexes (page 489) that include content from multiple fields. Continue reading for instructions and examples of building a compound index. Create a Compound Index (page 518), Indexing Tutorials (page 517) and Index Concepts (page 486) for more infor- mation. Some drivers may specify indexes, using NumberLong(1) rather than 1 as the specification. This does not have any affect on the resulting index. Note: To build or rebuild indexes for a replica set see Build Indexes on Replica Sets (page 521). 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. Although indexes can improve query performances, indexes also present some operational considerations. See Oper- ational Considerations for Indexes (page 149) for more information. To create an index, use createIndex() or a similar method from your driver$^{7}$. The createIndex() method only creates an index if an index of the same specification does not already exist. For example, the following operation creates an index on the userid field of the records collection: db.records.createIndex( { userid: 1 } ) 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 created index will support queries that select on the field userid , such as the following: db.records.find( { userid: 2 } ) db.records.find( { userid: { $gt: 10 } } ) But the created index does not support the following query on the profile_url field: db.records.find( { profile_url: 2 } ) For queries that cannot use an index, MongoDB must scan all documents in a collection for documents that match the query.