Created
September 24, 2014 00:22
-
-
Save TylerBrock/fffca6ffa49654f37b51 to your computer and use it in GitHub Desktop.
Spin up read only shard
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
var st = new ShardingTest({ | |
shards:1, | |
mongos:1, | |
other: { | |
rs: true, | |
numReplicas: 2, | |
separateConfig: true | |
} | |
}) | |
var mongos = st.s0; | |
var admindb = mongos.getDB('admin'); | |
admindb.runCommand({setParameter: 1, logLevel: 5}); | |
print("-------- LOG LEVEL 5 -------"); | |
db = mongos.getDB('wow'); | |
sh.enableSharding('wow'); | |
db.test.insert({ a: 1 }, { writeConcern: { w: 2 } }); | |
db.test.insert({ a: 2 }, { writeConcern: { w: 2 } }); | |
db.test.insert({ a: 3 }, { writeConcern: { w: 2 } }); | |
var cursor = db.test.find(); | |
while ( cursor.hasNext() ) { | |
printjson( cursor.next() ); | |
} | |
print("-------- Inserted Data -------"); | |
var primary = st.shard0.rs.getPrimary(); | |
primary.adminCommand({ "shutdown": 1 }) | |
print("-------- Shutdown Primary -------"); | |
rs.slaveOk(); | |
db.getMongo().setReadPref('secondary'); | |
cursor = db.test.find(); | |
while ( cursor.hasNext() ) { | |
printjson( cursor.next() ); | |
} | |
print("-------- Printed Data -------"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment