Skip to content

Instantly share code, notes, and snippets.

@dbmurphy
Created December 18, 2014 22:13
Show Gist options
  • Save dbmurphy/291431a56fbc6b15d029 to your computer and use it in GitHub Desktop.
Save dbmurphy/291431a56fbc6b15d029 to your computer and use it in GitHub Desktop.
Adding index and freeze all members of a replSet
user='XXXX';
pass='XXXX';
indexPattern={ 'Key' : 1 };
indexOptions={};
db.getSiblingDB('config').shards.find({},{host:1,_id:0}).forEach(function(shard){
tHosts = shard.host.split('/')[1].split(',')
tHosts.forEach(function(host){
print("Freezing "+ host);
x= new Mongo(host);
x.getDB('admin').auth(user,pass);
x.getDB('admin').getMongo().setSlaveOk(1);
x.getDB('admin').runCommand({replSetFreeze:60});
});
})
db.SearchKey.ensureIndex(indexPattern,indexOptions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment