HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How can we use transaction in mongodb standalone connection?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canstandalonemongodbtransactionhowuseconnection

Problem

I want to use transaction in mongodb but its told to replicaset can we perform transaction query with standalone mongodb if yes please share how to we can because when I try its give error

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

how to we perform translation without retryable writes.

Thanks

Solution

You can convert your standalone deployment to a single node replica set. Follow the tutorial to Convert a Standalone to a Replica Set, but do not add any additional members.

This will allow you to use features which require a replica set deployment (for example, transactions in MongoDB 4.0+ and change streams in MongoDB 3.6+).

The main downsides of a single member deployment are that you don't get any of the usual replica set benefits such as data redundancy and fault tolerance. A replica set member also has some expected write overhead as compared to a standalone server because it has to maintain a replication oplog.

A production replica set deployment should have a minimum of three members. See Deploy a replica set in the MongoDB documentation for full details.

Context

StackExchange Database Administrators Q#265236, answer score: 3

Revisions (0)

No revisions yet.