Skip to content

Instantly share code, notes, and snippets.

@sawanoboly
Created October 15, 2012 05:08
Show Gist options
  • Save sawanoboly/3890890 to your computer and use it in GitHub Desktop.
Save sawanoboly/3890890 to your computer and use it in GitHub Desktop.
mongorc.js: prompt with serverrole(mongos/config/replican-ode or single) and version.
prompt = function() {
// set version
version = db.version();
// case mongos
if (rs.status().info == 'mongos') {
return rs.status().info + ':[' + version + '] > ';
}
// config or replica
if (rs.status().set) {
role = rs.status().set;
} else if (db.serverCmdLineOpts().parsed.configsvr) {
role = 'config';
return role + ':[' + version + '] > ';
} else {
role = 'single';
return role + ':[' + version + '] > ';
}
// for replicasets
switch (rs.status().myState) {
case 1:
stateStr = 'PRIMARY'
break;
case 2:
stateStr = 'SECONDARY'
break;
case 7:
stateStr = 'ARBITER'
break;
}
return role + ':' + stateStr + ':[' + version + '] > ';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment