dj-nitehawk / MongoDB.Entities

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
https://mongodb-entities.com
MIT License
543 stars 69 forks source link

Does DB.Update lock row while update? #215

Closed kingsanu closed 9 months ago

kingsanu commented 9 months ago

I've 3 billing machin and they want latest stock from central database and that database habe only one row/document shared to 3 billing machine, so i want to ask does Db.Update() lock the row? if not than what can be other option, i seen findAndModify can help i think so how can i use then ?

dj-nitehawk commented 9 months ago

this is how you do a findAndModify in mongodb-entities.

here's how mongodb server handles concurrency, and the atomicity of findAndModify.

kingsanu commented 9 months ago

Dear sir, I understand that you have an option called UpdateAndGet. My inquiry is whether this option internally locks the row when another person is updating the same row. If it does, does another request wait until the first update is complete, or does it simply fail (the second request)?

dj-nitehawk commented 9 months ago

the library does nothing special regarding locking and ultimately delegates the call out to the mongo driver's FindOneAndUpdateAsync() method:

https://github.com/dj-nitehawk/MongoDB.Entities/blob/4746012d66d5b2132020d354d757b3bd50681b76/MongoDB.Entities/Builders/UpdateAndGet.cs#L471

here's the definitive answer to how mongo handles concurrency for write operations.