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

Build Indexes in the Background

On this page

By default, MongoDB builds indexes in the foreground, which prevents all read and write operations to the database while the index builds. Also, no operation that requires a read or write lock on all databases (e.g. listDatabases) can occur during a foreground index build.

Background index construction allows read and write operations to continue while building the index.

See also

Index Concepts and Indexing Tutorials for more information.


Background index builds take longer to complete and result in an index that is initially larger, or less compact, than an index built in the foreground. Over time, the compactness of indexes built in the background will approach foreground-built indexes.

After MongoDB finishes building the index, background-built indexes are functionally identical to any other index.


To create an index in the background, add the background argument to the createIndex() operation, as in the following index:

db.collection.createIndex( { a: 1 }, { background: true } )

Consider the section on background index construction for more information about these indexes and their implications.