4

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.

Parveen
  • 149
  • 1
  • 12

1 Answers1

4

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 :)

Vijay Rajpurohit
  • 1,266
  • 2
  • 13
  • 25
  • Well, one can issue `$currentOp` through the driver as an aggregation pipeline. – D. SM Apr 25 '20 at 13:48
  • @Oleg I'm not aware of it. :) – Vijay Rajpurohit Apr 25 '20 at 15:00
  • You can use it like a regular aggregation pipeline stage. – D. SM Apr 25 '20 at 16:16
  • @Oleg can you give me one example. I was thinking of workaround, using the async callback, but the version of Morphia 1.3.2 where the ensureIndex with async call back is not supported. – Parveen Apr 25 '20 at 20:01
  • in Ruby it looks like this: https://gist.github.com/p-mongo/67b3fbbfc916786d1abf4c0046910bfe – D. SM Apr 25 '20 at 20:10
  • @Oleg, with driver version I am using it, does not allow me to add aggregate pipeline and create an index. But thanks for the help. As part of next production we are planning to upgrade the version. – Parveen Apr 25 '20 at 23:03