繁体   English   中英

通过.Net驱动程序配置Mongo副本集

[英]Configure Mongo Replica Set via the .Net Driver

使用.Net驱动程序可以:

  • 检查某个Mongo实例是否已经是副本的一部分
  • 如果不创建副本
  • 添加\\从现有副本中删除节点

谢谢!

是。 但是在mongo shell中执行这些操作要容易得多,因为它已经定义了辅助函数。 查看副本集教程 对于在mongo shell中使用某个函数rs.initiate()例如rs.initiate()rs.add()每个步骤,您都可以通过在shell提示符下输入带有括号的函数名称来查看该函数的代码:

> rs.initiate
function (c) { return db._adminCommand({ replSetInitiate: c }); }
> rs.add
function (hostport, arb) {
    var cfg = hostport;

    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++;

    var max = 0;
    for (var i in c.members)
        if (c.members[i]._id > max) max = c.members[i]._id;
    if (isString(hostport)) {
        cfg = { _id: max + 1, host: hostport };
        if (arb)
            cfg.arbiterOnly = true;
    }
    if (cfg._id == null){
        cfg._id = max+1;
    }
    c.members.push(cfg);
    return this._runCmd({ replSetReconfig: c });
}

由于shell版本不同,您的shell中的代码可能略有不同。 我的外壳是3.0.1。 您可以将此代码用作在C#中编写这些函数自己的版本的指南。 您将使用RunCommand方法在服务器上运行诸如replSetReconfigreplSetInitiate类的命令。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM