Mongodb replica set, on localhost

Hello all,

I’d like to initiate a work process with replica set;

all of our servers had already set up with such.

thing is, locally, what’s the best practice (or convinience), should I actually set up rs (using run-rs for example) or should I convert a standalone mongodb to a replica set?

help would be much appreciated!


Hi @DaveJames,

When you are working locally, you just need a single node Replica Set (RS). There is no need to deploy a full 3 nodes RS on the same host. It will just consume more ressources and generate useless IOPS.

Usually when I work locally, I just use Docker and deploy a temporary node but you can also persist the data in a volume if you want to reuse it next time.

alias mdb='docker run --rm -d -p 27017:27017 -h $(hostname) --name mongo mongo:6.0.3 --replSet=test && sleep 4 && docker exec mongo mongosh --quiet --eval "rs.initiate();"'
alias m='docker exec -it mongo mongosh --quiet'

Single node RS also support Change Streams and Transactions just like a “normal” production ready 3 nodes RS.


1 Like

Hi @MaBeuLux88_xxx,

What should I do incase I run a local mongodb and do not use docker? is there an easy way of turning the local instance to rs?


make a copy of config file (usually /etc/mongo.conf) and edit its specific parts to suit your needs.

  • change IP and port
  • changes replica set name
  • change db and log path (create folders for them)
  • then just start mongod using that config file and “rs.initiate” (mongod --config rs_single.config)
  • connect at that port

alternatively you can fit all these options into a single command (provided folders exist)

mkdir ~/rs-single
mongod --dbpath ~/rs-single --fork --logpath ~/rs-single.log --replSet rssingle --bind_ip localhost --port 27077
mongo --port 27077

use this same method (edit as needed) anytime you want to test things freely.

1 Like

thanks @Yilmaz_Durmaz I’ll try that!

I would keep the default 27017 port for simplicity but yes that’s the equivalent without Docker. :slight_smile:

I use my Docker command line almost daily, especially when I’m working on the forum and I need to try something quickly and then trash the entire cluster.


1 Like