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()

--

--

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