Using transactions locally

Hello,
I’ve been writing my first application that uses MongoDB, it’s been going well. Now I have a need for transactions for the first time.

I followed this tutorial: https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-implement-transactions

I get “MongoError: This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.”

If I understand correctly, Transactions internally use “retryable writes”, and my local standalone server does not support it. Is my assumption correct?

Assuming the answer was yes, how do I get around this during development time?
Certainly, in production we will use a cloud-based mongodb with all the bells and whistles. However how can I get past this quickly on our dev machines without investing too much time?

Some of us use the mongodb binary directly, some use the docker image.

Hello @Nathan_Hazout, welcome to the forum.

Transactions documentation says:

  • In version 4.0 , MongoDB supports multi-document transactions on replica sets.
  • In version 4.2 , MongoDB introduces distributed transactions, which adds support for multi-document transactions on sharded clusters and incorporates the existing support for multi-document transactions on replica sets.

To use transactions on MongoDB 4.2 deployments (replica sets and sharded clusters), clients must use MongoDB drivers updated for MongoDB 4.2.

You will need at least MongoDB 4.0 replica-set to start working with transactions.

That said, setting up a replica-set quickly is very simple using mtools. With a single command you can setup a 3 node replica-set quickly. This should give you start in a development setup.