Lock with update aggregation pipeline

I know that MongoDB uses IX, IS, X, S level locks.

Updating the document uses IX locks at the collection level.

Since version 4.2, pipeline aggregation can be used for updates.

When doing a single document update (like using _id in the filter), does mongodb use IX lock at the collection level even if using the aggregation pipeline, not X lock at the collection level?

If used, can it be guaranteed that the update can happen atomically even if it goes through each $set stage?

(For example, while going through two $set stages, does another update request that modifies the same document wait in a pending state, or can it update between each $set stages?)

Hello @111479, welcome to the MongoDB Community forum!

When doing an update on a single document the operation is atomic - irrespective of it using the update operators or the update with aggregation pipeline. In fact, all write operations on a single document are atomic: see Update - Atomicity

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.