currently I face the following scenario: I have a dataset of 5k entities, which should be updated on my mongo db instance (currently MongoDB 4.2 but we will update to Mongo6 or 7 soon). All entities belong to the same collection. I want to use a multi-document transaction to make sure to update either all or none. I want to divide this huge package into smaller packages and send the updates via a 10 bulk write calls. Since we do some preprocessing, I would try to parallelize the whole process of preprocessing and sending.
In general, this is a problem since I have to take care of a strict order of the entity-updates send to the database IF they are casual related ( Read Isolation, Consistency, and Recency — MongoDB Manual). BUT in my case, the entities are guaranteed to be casually unrelated.
Now my question: If my entities are casually unrelated, I can parallelize the preprocessing and bulk-write requests via multiple threads and the mongo db driver or the mongo db server will take care of locking the collection and indices and organizing the requests so that at the end of the transaction a consistent db state (collection and indices) is guaranteed, right?
Thanks! And yes, i want to know whether i can use multiple bulk wirte operations in a single transaction but in parallel not just after each other. The only limit is found so far is that this can screw up everything if the entities are casually realted. But in generel, the mongo db has a nice locking system with reader and writer locks directly on database or collection level. So i think it might work.
Regarding the thread safty of the session, I will have a look at the C# driver. Thanks for that hint!
Edit: Well, according to your link, every driver HAS TO document whether they have implemented sessions thread safe or not. The c# driver docs don’t do that: Sessions and Transactions (mongodb.github.io)
…
All driver implementations will need to conform to that specification, (and java driver does mention that thread safety thing), so c# will not be an exception.
The answer for that is, no, you can’t have concurrent operations in a same session at the same time.
Hi,
yes … I re-read that paragraph after a few liters of coffee and now I agree. It is totally clear. Sorry.
That is bad for our performance. It result in a processing time factor of 10, so 10 times slower. Ok. I need a smarter solution. Thanks for your help!