Check the index creation progress in mongo DB using java driver

Tags: , , ,



I have around 10 millions of data in MongoDB. There is a requirement to add a new compound index. I used the following code to create the index. Using ensureIndex with option creation in background.

MongoStore.ads().ensureIndexes("MyCollection", MyCollection.class, true);

My question is how do I track the index creation progress. There are other sets of operations I need to do after confirming the Index is created 100%.

Please help me with how I do check the progress in java.

I am using mongo-java-driver 3.5 version.

Answer

You cann’t monitor them with mongo-java driver. But, you can monitor the created indexes in your Mongo shell:

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

This will return the output like:

Index Build (background) Index Build (background): 83727/271147 30%

For more about currentOp() refer here.

Hope this will help 🙂



Source: stackoverflow