How to run Mongo DB local as a replica set

akinncar

Akinn Rosa

Posted on December 21, 2022

How to run Mongo DB local as a replica set

In this post you will see how to run a Mongo DB server with replica set.

For this, we will use mongodb community that you can install from your therminal.

First, create a folder to store your data, like:
mkdir /data/mongodb/db0

Then, start your server with this command.
mongod --port 27017 --dbpath /data/mongodb/db0 --replSet rs0 --bind_ip localhost

After first start, you will need to start the replica set.
Open your SGBD (you can use Mongosh) and run this command:
rs.initiate()

Now, you can restar your server to apply all changes:
Run netstat -vanp tcp | grep 27017 in your therminal to get PID application, and kill then.
kill -9 81094 (modify 81094 to your PID)

Then, run
mongod --port 27017 --dbpath /data/mongodb/db0 --replSet rs0 --bind_ip localhost

That's It!

💖 💪 🙅 🚩
akinncar
Akinn Rosa

Posted on December 21, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related