Wednesday, January 1, 2025

Setup MongoDB ReplicaSet in Windows Machine

We're using the same machine for setting up the MongoDB ReplicaSet quickly, but with different port numbers.


1) Create these directories as below


mkdir D:\MongoDB\ReplicaSet












2) Start the mongod process for each replica.


mongod --bind_ip 192.168.56.1 --port 27019 --replSet rs0 --dbpath D:\MongoDB\Replicaset\data1 --oplogSize 200 --logpath D:\MongoDB\Replicaset\log1\log1.txt

mongod --bind_ip 192.168.56.1 --port 27020 --replSet rs0 --dbpath D:\MongoDB\Replicaset\data2 --oplogSize 200 --logpath D:\MongoDB\Replicaset\log2\log2.txt

mongod --bind_ip 192.168.56.1 --port 27021 --replSet rs0 --dbpath D:\MongoDB\Replicaset\data3 --oplogSize 200 --logpath D:\MongoDB\Replicaset\log3\log3.txt


--Bind_ip - is used to accept connections on a particular node. By specifying the IP address with --bind-ip, you're telling MongoDB to listen for incoming connections on that specific network interface of the node.

--replSet - to indicate the node is part of the replicaSet, but yet to configure command using rs.initiate after the processes from all the nodes started.

--OplogSize - option is used in the mongod process to specify the size of the oplog (operations log) for a replica set member. The oplog is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. 









3) Connect to Replica 1 and set variable:

>mongosh –port 27019

Store the current configuration of ReplicaSet in a variable and check it is set correctly:
















4) Execute rs.initiate(rconfig) command to start the replica set configuration process. 


>rs.initiate(rconfig)







5) Check the status of ReplicaSet after initialization

>rs.status()
























6) Run db.isMaster() command to see node status















Configured a MongoDB ReplicaSet successfully!


No comments:

Post a Comment

SQL Server TDE Database Encryption

This is Data-at-rest encryption. TDE is a feature that encrypts data files to protect them at rest. Databases to be encrypted: testdb, SAM 1...