An index build constructs an index while preserving access to the collection, coordinating replica-set voting, and committing or aborting consistently. MongoDB takes exclusive locks at the beginning and end, but permits interleaved reads and writes during construction. section 7.5
A replicated index build proceeds through these operational stages:
- The primary logs a startIndexBuild oplog entry; secondary members begin after replicating it. section 7.5
- Each data-bearing member indexes its collection data and votes to commit after completion. section 7.5
- While the primary waits for the voting quorum, secondary members incorporate new writes into the index. section 7.5
- The primary checks constraints such as duplicate keys, marks the index ready, and logs commitIndexBuild when validation succeeds. section 7.5
Table 7.1 Mongo build behavior for different versions
| MongoDB 7.1 |
Earlier MongoDB versions |
| During the collection scan phase, any index errors detected, except duplicate key errors, are reported immediately, and the index build is halted. |
Delays in reporting index build errors may occur because the errors are returned toward the end of the index build, in the commit phase. |
| If an index build encounters an error, a secondary member can instruct the primary member to halt the index build, preventing the secondary member from crashing. |
An error during an index build might lead to the crash of a secondary member. |
| An index build can be halted automatically if available disk space falls below the threshold specified in the |
An index build is not halted due to insufficient available disk space. |
Compare MongoDB 7.1 with earlier behavior for error reporting, secondary failure handling, and disk-space safeguards. section 7.5
Monitor or stop a build
Use db.adminCommand({ currentOp: true, $or: [ { op: "command", "command.createIndexes": { $exists: true } }, { op: "command", "command.$truncated": /^\{ createIndexes/ }, { op: "none", "msg": /^Index Build/ } ] }) to inspect active builds. Use dropIndexes, dropIndex(), or dropIndexes() to halt one; do not use killOp in replica sets or sharded clusters. section 7.5.1 section 7.5.2
