Docker mongodb with shared cluster on 1 machine

Hello i use mongodb 5 on local machine for locale developing as Standalone Cluster.

Today i try use transaction and found:

System.NotSupportedException: Standalone servers do not support transactions.

Okey. I recreate docker container:

docker run --name mongo_shard -p 27017:27017 -d mongo --shardsvr --replSet shard01

But cant connect to mongo . I try by Compass and Nosqlmanager.

I want to draw attention to the first line. These are definitely not connection problems

What is problem?

last logs from container: without errors / exceptions

–shardsvr is a configuration used in a sharded cluster. If this is a single node / standalone then you don’t need this setting. The node is looking for a sharded cluster to be added too but there isn’t one. If you look in the logs you will see a message “sharding state not initialized”.

what should i do for run mongo in shared mode on 1 locale machine for developing?

I can’t find any instructions for this option for docker. All the instuctions about how to turn on lots of machines

Hi @alexov_inbox,

If you want to set up a development MongoDB server that supports transactions, you can convert your standalone server to a single-member replica set: Convert a Standalone to a Replica Set.

Transactions are only supported in a replica set or sharded cluster deployment because transactions require an operations log (oplog) with the history of data changes.

You’re almost there based on your first post, but:

  • As suggested by @tapiocaPENGUIN, remove the --shardsvr parameter since you are not creating a sharded cluster

  • Run rs.initiate() to initiate the new replica set (only required once, when you create a new replica set)

  • Connect to this deployment using a replica set connection string. Based on your post above, that should be similar to:



1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.