Monitor and abort an in-progress index build
MongoDBMaintenanceCommand
// Index builds in progress and their completion percentage:
db.getSiblingDB("admin").aggregate([
{ $currentOp: { allUsers: true } },
{ $match: { $or: [{ "command.createIndexes": { $exists: true } }, { desc: /^IndexBuildsCoordinator/ }] } },
{ $project: { opid: 1, desc: 1, ns: 1, secs_running: 1, msg: 1, progress: 1, "command.indexes.name": 1 } }
])
// Abort the build (on the primary; in a replica set it stops on all members):
db.musteri.dropIndex("idx_email")What it does
Lists running index builds with the number of documents scanned and the percentage progress (progress.done / progress.total); if needed, aborts the build with dropIndex.
When to use it
To estimate when a createIndex started on a large collection will finish, or to stop a build that creates load at peak time.
Caution
Abort an index build with dropIndex/dropIndexes, not killOp; in a replica set run it on the primary so the abort propagates to all members. Some DDL operations on the collection wait during the build. A short exclusive lock is taken at the end of the build; under very heavy writes that moment can cause latency.