How to verify that a Background Index has finished building

Hi MongoDB Community,

I’m currently working on creating a new background Index on an existing collection in a MongoDB 4.0.23 database.

I’ve been reading the Mongo docs on how to check on the index building progress using the db.admin Command(), but it’s not quite clear how to verify that the index has finished building. (https://docs.mongodb.com/manual/reference/method/db.currentOp/#active-indexing-operations).

Does it make sense to just be running the db.adminCommand() every X minutes and wait until we no longer see a % complete message and then we know the background index is done building? Or is there a better way of verifying when a background index has been completely built?

To test, I’ve run the db.adminCommand on my local server (where the background index was created a long time ago) and I get a sensible result with an empty inprog array. I’m assuming I’d see the same empty inprog array once our index is built on our production database. It’s just hard to test the background index build process on a local server that has a tiny data set and the background index builds faster than I can check for progress.

Here’s the result I see locally when running the db.adminCommand referenced in the Mongo documentation.

{
    "inprog" : [],
    "ok" : 1.0,
    "operationTime" : Timestamp(1631660277, 4),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1631660277, 4),
        "signature" : {
            "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" },
            "keyId" : NumberLong(0)
        }
    }
}