Does createIndex return before the index build is complete in MongoDB 4.2+?

When using createIndex in MongoDB 4.2+(Node.js driver), the docs say that all indexes are created in the foreground with exclusive locks only in the beginning and end of the operation. But will the actual createIndex function resolve before the index build is complete? Or will it resolve once the index has been completely built and is ready for use?

Hi :wave: @Anders_Fjeldstad,

Welcome to the MongoDB Community forums :sparkles:

Based on my understanding, it resolves once the index is completely built unless the background: true option is specified. For further information on this topic, please refer to the createIndex - Node.js Driver Documentation.

I hope it helps. Please let us know if you have any further questions.


Ok so since the background option is deprecated and ignored from 4.2 and onwards, createIndex should now resolve only after the full index build is done, is that correct?