MongoDB demo on Replica Set

$ pwd
$ mkdir -p data/rs1 data/rs2 data/rs3

Step #01: Start the nodes

$  mongod --replSet rs1 --logpath "1.log" --dbpath ./rs1 --port 27017 --fork$  mongod --replSet rs1 --logpath "2.log" --dbpath ./rs2 --port 27018 --fork$  mongod --replSet rs1 --logpath "3.log" --dbpath ./rs3 --port 27019 --fork

Step #02: Setting the Replica Set

config = { _id: "rs1", members:[
{ _id : 0, host : "localhost:27017", priority:0, slaveDelay:5 },
{ _id : 1, host : "localhost:27018"},
{ _id : 2, host : "localhost:27019"} ]
script init_replica_pablo.js
mongo --port 27018 < init_replica_pablo.js

Step #03: Insert Data in Primary

$ mongo --port 27018
Insert data in primary

Step #04: What is happening on Secondary

verify on secondary with: rs.slaveOk()

Step #05: Shut down Primary!

mongo:27018 was the PRIMARY

Step #05.i ~ Verify status with

rs.stats() — we see the PRIMARY{ ns : “test.people”}).pretty()
rs1:PRIMARY>{ ns : “test.people”}).pretty()
rs1:PRIMARY>{ ns : “test.people”}).pretty()
rs1:SECONDARY>{ ns : “test.people”}).pretty()

Step #05.ii ~ Shut Down Primary

mongo:27018 was the PRIMARY
Before KILL PRIMARY in Replica Set
After KILL PRIMARY in Replica Set — 27019 is the new king!





#cloud . #mobile ~} Sharing IT while learning It! ... Opinions are for my own

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Heroku vs. AWS: Which Cloud Solution is Best in 2022

How DynamoDB’s Pricing Works, Gets Expensive Quickly and the Best Alternatives

Creating a Differentiation Strategy: What It Is and How To Create One

Journey from LFI to RCE with /proc/self/fd/ !!!

Deploying NextCloud on EKS and Integrating AWS EFS and ELB

Create a Symfony 5 application with Docker(part 1)

I’m teaching software engineering, so why does version control come first?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Pablo Ezequiel Inchausti

Pablo Ezequiel Inchausti

#cloud . #mobile ~} Sharing IT while learning It! ... Opinions are for my own

More from Medium

GitHub site hosting using react js and git-hub API

Getting started with MongoDB Part 2

Adding correlation-id to Node.js express-based application with log4js