mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
add rs.remove helper SERVER-1676
This commit is contained in:
parent
f6d50d5138
commit
95b93e4119
@ -1265,6 +1265,7 @@ const StringData _jscode_raw_utils =
|
||||
"print(\"\\trs.add(membercfgobj) add a new member to the set with extra attributes\");\n"
|
||||
"print(\"\\trs.addArb(hostportstr) add a new member which is arbiterOnly:true\");\n"
|
||||
"print(\"\\trs.stepDown() step down as primary (momentarily)\");\n"
|
||||
"print(\"\\trs.remove(hostportstr) remove a host from the replica set\");\n"
|
||||
"print(\"\\trs.conf() return configuration from local.system.replset\");\n"
|
||||
"print(\"\\trs.slaveOk() shorthand for db.getMongo().setSlaveOk()\");\n"
|
||||
"print();\n"
|
||||
@ -1294,11 +1295,28 @@ const StringData _jscode_raw_utils =
|
||||
"}\n"
|
||||
"c.members.push(cfg);\n"
|
||||
"return db._adminCommand({ replSetReconfig: c });\n"
|
||||
"}\n"
|
||||
"rs.stepDown = function () { return db._adminCommand({ replSetStepDown:true}); }\n"
|
||||
"};\n"
|
||||
"rs.stepDown = function () { return db._adminCommand({ replSetStepDown:true}); };\n"
|
||||
"rs.addArb = function (hn) { return this.add(hn, true); }\n"
|
||||
"rs.conf = function () { return db.getSisterDB(\"local\").system.replset.findOne(); }\n"
|
||||
"\n"
|
||||
"rs.remove = function (hn) {\n"
|
||||
"var local = db.getSisterDB(\"local\");\n"
|
||||
"assert(local.system.replset.count() <= 1, \"error: local.system.replset has unexpected contents\");\n"
|
||||
"var c = local.system.replset.findOne();\n"
|
||||
"assert(c, \"no config object retrievable from local.system.replset\");\n"
|
||||
"c.version++;\n"
|
||||
"\n"
|
||||
"for (var i in c.members) {\n"
|
||||
"if (c.members[i].host == hn) {\n"
|
||||
"c.members.splice(i, 1);\n"
|
||||
"return db._adminCommand({ replSetReconfig : c});\n"
|
||||
"}\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"return \"error: couldn't find \"+hn+\" in \"+tojson(c.members);\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"help = shellHelper.help = function (x) {\n"
|
||||
"if (x == \"connect\") {\n"
|
||||
"print(\"\\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.\");\n"
|
||||
|
@ -1260,6 +1260,7 @@ rs.help = function () {
|
||||
print("\trs.add(membercfgobj) add a new member to the set with extra attributes");
|
||||
print("\trs.addArb(hostportstr) add a new member which is arbiterOnly:true");
|
||||
print("\trs.stepDown() step down as primary (momentarily)");
|
||||
print("\trs.remove(hostportstr) remove a host from the replica set");
|
||||
print("\trs.conf() return configuration from local.system.replset");
|
||||
print("\trs.slaveOk() shorthand for db.getMongo().setSlaveOk()");
|
||||
print();
|
||||
@ -1294,6 +1295,23 @@ rs.stepDown = function () { return db._adminCommand({ replSetStepDown:true}); }
|
||||
rs.addArb = function (hn) { return this.add(hn, true); }
|
||||
rs.conf = function () { return db.getSisterDB("local").system.replset.findOne(); }
|
||||
|
||||
rs.remove = function (hn) {
|
||||
var local = db.getSisterDB("local");
|
||||
assert(local.system.replset.count() <= 1, "error: local.system.replset has unexpected contents");
|
||||
var c = local.system.replset.findOne();
|
||||
assert(c, "no config object retrievable from local.system.replset");
|
||||
c.version++;
|
||||
|
||||
for (var i in c.members) {
|
||||
if (c.members[i].host == hn) {
|
||||
c.members.splice(i, 1);
|
||||
return db._adminCommand({ replSetReconfig : c});
|
||||
}
|
||||
}
|
||||
|
||||
return "error: couldn't find "+hn+" in "+tojson(c.members);
|
||||
};
|
||||
|
||||
help = shellHelper.help = function (x) {
|
||||
if (x == "connect") {
|
||||
print("\nNormally one specifies the server on the mongo shell command line. Run mongo --help to see those options.");
|
||||
|
Loading…
Reference in New Issue
Block a user