Fix retryWrites=false in nodejs and mongodb

Viewed 2706

I am using node v12.16.3, mongodb 4.2 via docker(Official image) and mongodb driver v3.5.8. When I apply my insertOne operation within a transaction I get the following error:

This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.

Here is my connection url: mongodb://root:root@localhost:27017 Adding retryWrites=false doesn't work (mongodb://root:root@localhost:27017/?retryWrites=false)

Here is how I create mongo client:

const { MongoClient } = require('mongodb');

const client = new MongoClient('mongodb://root:root@localhost:27017/?retryWrites=false', {
    useNewUrlParser: true,
    useUnifiedTopology: true
});

I intentionally don't specify a default database cause there is no default database, later I used a specific one depending on my business cases:

const db = client.db('somedatabae')

Any ideas whether I am doing something wrong or there is something else? Thanks in advance.

1 Answers

Thanks to D.SM, it really happened that I had to set up a replica set. After that everything worked.

Related