Will insertOne lock the collection?

In MongoDB, if we update a Document the operation is atomic. I believed this is achieved by having an X lock on the Document.

When we do insertOne into a collection, will it lock the collection? For example, if I have multiple threads doing insertOne into the same collection concurrently (each inserted Doc is unique), can all the insertions be done concurrently ?

Using MongoDB v5.0+

1 Like

i’m not sure about the internal, but i believe yes, they can run concurrently.

According to official doc, insert uses an IX lock on coll and db. I’m not able to find the related information for mongodb, but at least in Mysql, IX lock is compatible with another IX lock

1 Like