Create a MongoDB replica set in Windows

Add replication options into MongoDB config file

replication:
oplogSizeMB: <int>
replSetName: <string>
enableMajorityReadConcern: <boolean>
replication:
replSetName: rs0

Convert a standalone instance to a replica set

mongod --port 27017 --replSet rs0 --dbpath="C:\data\db0"
rs.initiate()

Add new members to the replica set

mongod --port 27027 --replSet rs0 --dbpath="C:\data\db1"
mongod --port 27037 --replSet rs0 --dbpath="C:\data\db2"
rs.add( { host: "127.0.0.1:27027", priority: 0, votes: 0 } )
rs.add( { host: "127.0.0.1:27037", priority: 0, votes: 0 } )

Check replica set status

rs.status()

--

--

--

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

Recommended from Medium

AWS WAF Captcha

Fix Call quality issues if you’re using VoIP Business phone service to work remotely from home or…

Fix Common VoIP Call Quality Issues

Configuration of Apache Webservers Dynamically using Ansible on AWS

Continuous delivery with Jenkins Pipelines

Chapter 7: Coding the Application

Noobie Teach SQL

Cross Domain Tracking — Share Marketing Cloud ID with your other domains

SIMPLIFYING OPERATIONS FOR KUBERNETES CLUSTERS AND CLOUD APPS

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
Adela Chao

Adela Chao

More from Medium

Introduction to Node.js, Koa.js and REST Services

Parsing site with Node JS

Create Node js-express API from Scratch

Online Compilier using Node.JS