summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <redbeard0531@gmail.com>2010-10-26 00:21:04 -0400
committerMathias Stearn <redbeard0531@gmail.com>2010-10-26 01:19:18 -0400
commit954574cff3cfd26ae598098f5b9b890699e665d8 (patch)
tree2d7fb95ee951bef8587e006945ac3643ea1d309f
parent1f57383462db6a754c99abb3208a1fb985f67918 (diff)
downloadmongo-954574cff3cfd26ae598098f5b9b890699e665d8.tar.gz
add rs.remove helper SERVER-1676
Conflicts: shell/mongo_vstudio.cpp
-rw-r--r--shell/utils.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/shell/utils.js b/shell/utils.js
index de26403afa6..0a22088d12c 100644
--- a/shell/utils.js
+++ b/shell/utils.js
@@ -1056,6 +1056,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();
@@ -1090,6 +1091,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.");