mongodb status of index creation job

MongodbBackgroundIndexingJobs

Mongodb Problem Overview


I'm using MongoDB and have a collection with roughly 75 million records. I have added a compound index on two "fields" by using the following command:

db.my_collection.ensureIndex({"data.items.text":1, "created_at":1},{background:true}).

Two days later I'm trying to see the status of the index creation. Running db.currentOp() returns {}, however when I try to create another index I get this error message:

cannot add index with a background operation in progress.

Is there a way to check the status/progress of the index creation job?

One thing to add - I am using mongodb version 2.0.6. Thanks!

Mongodb Solutions


Solution 1 - Mongodb

At the mongo shell, type below command to see the current progress:

rs0:PRIMARY> db.currentOp(true).inprog.forEach(function(op){ if(op.msg!==undefined) print(op.msg) })

Index Build (background) Index Build (background): 1431577/55212209 2%

Solution 2 - Mongodb

You could use currentOp with a true argument which returns a more verbose output, including idle connections and system operations.

db.currentOp(true)

... and then you could use db.killOp() to Kill the desired operation.

Solution 3 - Mongodb

The following should print out index progress:

db
  .currentOp({"command.createIndexes": { $exists : true } })
  .inprog
  .forEach(function(op){ print(op.msg) })

outputs:

Index Build (background) Index Build (background): 5311727/27231147 19%

Solution 4 - Mongodb

Unfortunately, DR9885 answer didn't work for me, it has spaces in the code (syntax error) and even if the spaces are removed, it returns nothing.

This works as of Mongo Shell v3.6.0

db.currentOp().inprog.forEach(function(op){ if(op.msg) print(op.msg) })

Didn't read Bajal answer until after I posted mine, but it's almost exactly the same except that it's slightly shorter code and also works.

Solution 5 - Mongodb

I like:

db.currentOp({ 
    'msg' :{ $exists: true },
    'command': { $exists: true },
    $or: [ 
        { 'command.createIndexes': { $exists: true } }, 
        { 'command.reIndex': { $exists: true } }
    ]
}).inprog.forEach(function(op) { 
    print(op.msg); 
});

Output example:

> Index Build Index Build: 84826/335739 25%

Documentation suggests:

db.adminCommand(
    {
      currentOp: true,
      $or: [
        { op: "command", "command.createIndexes": { $exists: true }  },
        { op: "none", "msg" : /^Index Build/ }
      ]
    }
)

Active Indexing Operations example.

Solution 6 - Mongodb

Simple one to just check progress of a single index going on:

db.currentOp({"msg":/Index/}).inprog[0].progress;

outputs:

{ "done" : 86007212, "total" : 96868386 }

Solution 7 - Mongodb

Find progress of index jobs, nice one liner:

> db.currentOp().inprog.map(a => a.msg)
[
	undefined,
	undefined,
	undefined,
	undefined,
	undefined,
	undefined,
	"Index Build: scanning collection Index Build: scanning collection: 16448156/54469342 30%",
	undefined,
	undefined
]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYair AvgarView Question on Stackoverflow
Solution 1 - MongodbBajalView Answer on Stackoverflow
Solution 2 - MongodbCesarTrigoView Answer on Stackoverflow
Solution 3 - MongodbDR9885View Answer on Stackoverflow
Solution 4 - MongodbComputer's GuyView Answer on Stackoverflow
Solution 5 - MongodbFPCView Answer on Stackoverflow
Solution 6 - MongodbIan MarettView Answer on Stackoverflow
Solution 7 - MongodbPhil PooreView Answer on Stackoverflow