Does findOneAndUpdate perform updates atomically? (As findAndModify is not available in Java MongoDB async driver) [duplicate]
Asked Answered
Q

1

6

I am using MongoDB's Java Async Driver version 3.6, I don't see a findAndModify implemented as part of MongoCollection Class (am I mistaken?), the closest thing is findOneAndUpdate can someone confirm that this operation will be performed atomically?

I understand how concurrent updates happen. The question is very specific are atomic ( read+write) guarantees atomic for the findOneAndUpdate api or not. It is not the same as asking how to use findAndmodify.

Quadrifid answered 17/5, 2018 at 13:58 Comment(0)
H
3

According to these docs , single write transactions are atomic. So with findOneAndUpdate, this would indeed be atomic. If you are doing batch writes or updates for example, then each action individually is atomic but not all of the actions as a whole.

Heartworm answered 17/5, 2018 at 14:11 Comment(3)
thanks I did read that bit but I couldn't infer from that, that the (search + write) itself will be atomic.Quadrifid
@Quadrifid So is (search + write) atomic? Asking you since you have not accepted the answer.Froufrou
I dont know anymore I had thought of looking up the source or asking the developer list. I don't agree with the inference drawn from the referred document.Quadrifid

© 2022 - 2024 — McMap. All rights reserved.