0
votes

Step1- I have following collections in my main db [running on port 27017]

$mongo

$show dbs

show dbs DB 0.078GB

admin (empty)

auditing

local

university

test

Step2- Now I am creating replica using below command

$mongod --dbpath ~/mongodb_data_dir/mongo/data0 --replSet auditlogreplySet --port 27018

$mongod --dbpath ~/mongodb_data_dir/mongo/data1 --replSet auditlogreplySet --port 27019

$mongod --dbpath ~/mongodb_data_dir/mongo/data2 --replSet auditlogreplySet --port 27020

Step3- running mongo for port 27018

$ mongo --port 27018

$show dbs

admin (empty)

local 0.328GB

Query: is it possible to sync all dbs from port 27017(main DB) to replica 27018? Please help. so that I can see all the dbs existing in main db in replica set.

1

1 Answers

0
votes

As per the above post, you have just created the replica set members. you need to add these replica members to the PRIMARY NODE first.

In main db [running on port 27017] , run the below commands :

rs.initiate(); // this command will make this NODE as PRIMARY.

// To add the secondary replica members, use the below command, run these in the same main DB shell :

rs.add (machineName:port);

// once you are done, on each of the secondary replica shell, exceute the below command

rs.slaveOk();

// once you are done, it will sync all the dbs from the primary node.