Last active
August 29, 2015 14:16
-
-
Save scott4dev/b71d6ef27c6cd1e1b18f to your computer and use it in GitHub Desktop.
Deploy a Replica Set for Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//start mongod instances | |
mongod --port 27017 --dbpath data/rs0-0 --replSet rs0 --smallfiles --oplogSize 128 | |
mongod --port 27018 --dbpath data/rs0-1 --replSet rs0 --smallfiles --oplogSize 128 | |
mongod --port 27019 --dbpath data/rs0-2 --replSet rs0 --smallfiles --oplogSize 128 | |
//add primary | |
rsconf = { | |
_id: "rs0", | |
members: [ | |
{ | |
_id: 0, | |
host: "localhost:27017" | |
} | |
] | |
} | |
rs.initiate( rsconf ) | |
rs.conf() | |
//add secondaries | |
rs.add("localhost:27018") | |
rs.add("localhost:27019") | |
//add some data | |
db.users.insert({name:"G"}) | |
db.users.insert({name:"P"}) | |
db.users.insert({name:"A"}) | |
db.users.insert({name:"S"}) | |
//do a query | |
db.users.find() | |
//to read from SECONDARY use | |
rs.slaveOk() | |
//set 0 priority | |
cfg = rs.conf() | |
cfg.members[2].priority = 0 | |
rs.reconfig(cfg) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment