00466802 - Split Replica Set killall mongod rm -rf repl3 mkdir repl3 mlaunch init --replicaset --nodes 3 --dir repl3 --hostname localhost uri="mongodb://localhost:27017,localhost:27018,localhost:27019/?replicaSet=replset" m="mongo $uri --eval" sleep 5 $m "db.mycoll.insert({a:1})" # copy one of the nodes to 2 new locations rm -rf newrepl mkdir newrepl cp -R repl3/replset/rs2 newrepl/rs1 cp -R repl3/replset/rs2 newrepl/rs2 # start both standalones using the copies mongod --dbpath newrepl/rs1/db --logpath newrepl/rs1/mongod.log --port 28017 --fork --wiredTigerCacheSizeGB 1 mongod --dbpath newrepl/rs2/db --logpath newrepl/rs2/mongod.log --port 28018 --fork --wiredTigerCacheSizeGB 1 dropLocal="db = db.getSiblingDB('local'); db.dropDatabase(); db = db.getSiblingDB('admin'); db.shutdownServer()" # drop the local database mongo --port 28017 --eval "$dropLocal" mongo --port 28018 --eval "$dropLocal" # startup repl1 as a new replica set mongod --dbpath newrepl/rs1/db --logpath newrepl/rs1/mongod.log --port 28017 --fork --wiredTigerCacheSizeGB 1 --replSet newrepl # run rs.initiate mongo --port 28017 --eval "rs.initiate()" rm -rf dump # dump the local database - including the system.replset collection mongodump --port 28017 --db local mongodump --port 28017 --db local --collection system.replset # start the second node as a standalone and restore the local database mongod --dbpath newrepl/rs2/db --logpath newrepl/rs2/mongod.log --port 28018 --fork --wiredTigerCacheSizeGB 1 mongorestore --port 28018 --db local dump/local #shutdown the second node mongo --port 28018 --eval "db = db.getSiblingDB('admin'); db.shutdownServer()" # to prove that the initial sync does not happen, add a collection that will not exist in the second node once it is joined as a replica set # mongo --port 28017 --eval "db.phantom.insert({text: 'only exists in 28017'})" # start the second node with the replset newrepl mongod --dbpath newrepl/rs2/db --logpath newrepl/rs2/mongod.log --port 28018 --fork --wiredTigerCacheSizeGB 1 --replSet newrepl # connect to the first node and run rs.add mongo --port 28017 --eval "rs.add('Arnies-MacBook-Pro.local:28018')"