If your application includes createIndex() operations, and an index doesn’t exist for other operational concerns, building the index can have a severe impact on the performance of the database. 

To avoid performance issues, make sure that your application checks for the indexes at start up using the getIndexes() method or the equivalent method for your driver 4 and terminates if the proper indexes do not ex- ist. Always build indexes in production instances using separate application code, during designated maintenance windows. 

## Interrupted Index Builds 

If a background index build is in progress when the mongod process terminates, when the instance restarts the index build will restart as foreground index build. If the index build encounters any errors, such as a duplicate key error, the mongod will exit with an error. 

To start the mongod after a failed index build, use the storage.indexBuildRetry or --noIndexBuildRetry to skip the index build on start up. .. _index-creation-building-indexes-on-secondaries: 

## Building Indexes on Secondaries 

Changed in version 2.6: Secondary members can now build indexes in the background. Previously all index builds on secondaries were in the foreground. 

Background index operations on a replica set secondaries begin after the primary completes building the index. If MongoDB builds an index in the background on the primary, the secondaries will then build that index in the back- ground. 

To build large indexes on secondaries the best approach is to restart one secondary at a time in standalone mode and build the index. After building the index, restart as a member of the replica set, allow it to catch up with the other members of the set, and then build the index on the next secondary. When all the secondaries have the new index, step down the primary, restart it as a standalone, and build the index on the former primary. 

The amount of time required to build the index on a secondary must be within the window of the oplog , so that the secondary can catch up with the primary. 

Indexes on secondary members in “recovering” mode are always built in the foreground to allow them to catch up as soon as possible. 

See Build Indexes on Replica Sets (page 521) for a complete procedure for building indexes on secondaries. 

## Index Names 

The default name for an index is the concatenation of the indexed keys and each key’s direction in the index, 1 or -1. 

## Example 

Issue the following command to create an index on item and quantity : 

db.products.createIndex( { item: 1, quantity: -1 } ) 

The resulting index is named: item_1_quantity_-1 . 

Optionally, you can specify a name for an index instead of using the default name. 

## Example 

