...
To use MongoDB Transactions - we have to have the MongoDB setup in ReplicSet mode AND we have to make configuration/setup changes with our ESR Microservices.
MongoDB ReplicaSets
Simply put, a MongoDb ReplicaSet is a cluster in primary/secondary mode. All writes are sent to the master and then the data is propagated to the secondaries. You can setup a MongoDB ReplicaSet with just one node - this is good for testing Transactions but a single node ReplicaSet is not a good idea for production use cases.
If a MongoDB is setup in ReplicaSet mode, it will generally have “replicaSet=
” within it’s MongoDB connection string. Here’s an example of a mongodb connection string for a replicaset:mongodb://txuser:txpass@mongo1.hee.com:27011,mongo2.hee.com:27012,mongo3.hee.com:27013/transdb?authSource=transdb&replicaSet=rs0
For further details see
NOTE: if we want to use MongoDB Transactions we must point to a MongoDB in ReplicaSet mode AND setup the code to use Transactions.
We cannot have the code to setup to use transactions and point to a MongoDB not in ReplicaSet (Transaction supporting) mode.
We cannot have the code setup without transaction support and point to a MongoDB in ReplicaSet (Transaction supporting) mode.
If we have the code setup with transaction support we must point to a MongoDB in ReplicaSet (Transaction supporting mode)
If the code is setup without transaction support we must point to a MongoDB not in ReplicSet (Transaction supporting mode)
In the code, there are 3 steps required to use MongoDB Transactions.
...