Skip to content

Instantly share code, notes, and snippets.

@TylerBrock
Created September 24, 2014 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylerBrock/fffca6ffa49654f37b51 to your computer and use it in GitHub Desktop.
Save TylerBrock/fffca6ffa49654f37b51 to your computer and use it in GitHub Desktop.
Spin up read only shard
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