Hi,
I have a question about transactions.
Imagine the following scenario:
We have a “Car”, with 4 "Wheel"s. These are stored in different collections and the Wheel object has a CarId property.
We also have the Archived property on all entities.
When we are archiving our Car, we are also cascading down to its Wheels and archiving them aswell.
This is done by having a custom MongoDbAdapter where T is either Car or Wheel.
The documentation states: “Use an IClientSession only with the MongoClient (or associated MongoDatabase or MongoCollection) that created it. Using an IClientSession with a different MongoClient results in operation errors.”
We have made a “transaction wrapper” with a Scoped lifetime which creates a new IClientSession if it does not exist, and reuses the existing if it already exists.
Then on the root level (our Car in this case), we are calling StartTransaction, CommitTransaction etc (with the MongoClient that created the ClientSession).
On our Wheels, none of the session methods get called - but we do send the ClientSession through to our operation, e.g. “UpdateOne(session, filter, entity)”.
We are unsure about the warning in the documentation - is it faulty to send the ClientSession through as we’re doing?
We could likely end up in a scenario where we send the session created by MongoClient_1 to an operation made by MongoClient_2 - and this seems to be working according to our tests.
Is it okay to send a session created by another client down to an operation? Or what potential problems could we face - or are we simply misunderstanding the Warning text in the documentation?
Kind regards,
Emil