mongodb 主从服务器

@set mongod=..inmongod.exe

set keyFile=key.key

if not exist %keyFile% (
echo 123456>%keyFile%
)

md %1 2>nul 1>nul

%mongod% --port %1 --replSet %2 --dbpath %1 --logpath %1\_output_%1.log %3 %4 %5 %6

::接着运行↓
config_rs1 = {
    _id: "rs",
    members: [{
        _id: 0,
        host: "127.0.0.1:27017",
        priority: 4
    },
    {
        _id: 1,
        host: "127.0.0.1:27018",
        priority: 3
    },
    {
        _id: 2,
        host: "127.0.0.1:27019",
        priority: 2
    },
    {
        _id: 3,
        host: "127.0.0.1:27020",
        priority: 1
    }]
};

rs.initiate(config_rs1);
原文地址:https://www.cnblogs.com/arliang/p/3273060.html