Atomicity of indexes creation

Hi everyone!
In my app I need to be sure that indexes had been created before collection operations. For example, I must be sure that ALL indexes had been created before Create document operation.
So my question is: can I get the situation when some indexes were created then command was performed then other indexes were created if indexes creation and my command are executed in parallel? I use C# driver

I don’t fully understand your question. But this explains how a new index is built on a non-empty collection.

You can also

Use db.currentOp() to monitor the progress of ongoing index builds.

1 Like

I mean that in the first thread I do indexes creation (they are background indexes actually if it makes sense) with command Collection.Indexes.CreateManyAsync() and in the other thread I do some operation using this collection, for example, document insertion. My collection is empty before both indexes creation and document insertion.

Let’s consider the situation when we want to create 5 background indexes. We do Collection.Indexes.CreateManyAsync() and document insertion at the same time. Can this thing happen: 3 indexes were created then document was inserted then other 2 indexes were created?

Out of interest why does it matter? In only doing inserts and index creation why does itmattet which fimishes first.

If we have a unique index on some field and firstly we create index and secondly do 2 documents insertion having the same field then we get an error on the second insertion. This is desirable behaviour. But if we firstly do these docs insertion and then create indexes then we get an error on index creation and this isn’t desirable.