I’m working with a 10 year old service originally written against MongoDB 2.4, and currently on 3.6. The service relies on several unique indexes to maintain data integrity, which means those indexes must exist at all time the service is active. As such, the service calls ceateIndex
on all indexes at startup and if any are missing (which generally shouldn’t happen, but…) blocks until they’re built.
We’re looking to finally get off an EOL version of Mongo, but the new index build method is concerning as it allows writes during the build, and those writes can violate the unique
constraint. I haven’t been able to find any method to ensure the index is built other than polling currentOp
/ getIndexes
to check the build status. Is there some way to force clients to block on a createIndex
call, or an equivalent way of ensuring the indexes are built before completing service startup?