我想知道如何将我的mongo客户端连接到我的复制集

时间:2016-07-23 17:30:10

标签: mongodb database-connection replication

我意识到数据oplog.rs与我的客户端oplog.rs不同。一旦启动复制集,连接是否应该是自动的?或者我在这个过程中错过了一个步骤。

我正在关注本教程http://www.acemyskills.com/replica-sets-in-mongodb/

    config = {
        _id:"acemyskillsrepsets", 
        members: [
            {_id: 0, host: "localhost:27017"},
            {_id: 1, host: "localhost:27018"},
            {_id: 2, host: "localhost:27019"}
        ]
    };acemyskillsrepsets:PRIMARY> rs.status()
{
        "set" : "acemyskillsrepsets",
        "date" : ISODate("2016-07-24T01:35:16.869Z"),
        "myState" : 1,
        "term" : NumberLong(19),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "members" : [
                {
                        "_id" : 0,
                        "name" : "localhost:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 63,
                        "optime" : {
                                "ts" : Timestamp(1469324080, 1),
                                "t" : NumberLong(19)
                        },
                        "optimeDate" : ISODate("2016-07-24T01:34:40Z"),
                        "electionTime" : Timestamp(1469324079, 1),
                        "electionDate" : ISODate("2016-07-24T01:34:39Z"),
                        "configVersion" : 2,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "localhost:27018",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 25,
                        "optime" : {
                                "ts" : Timestamp(1469324080, 1),
                                "t" : NumberLong(19)
                        },
                        "optimeDate" : ISODate("2016-07-24T01:34:40Z"),
                        "lastHeartbeat" : ISODate("2016-07-24T01:35:15.260Z"),
                        "lastHeartbeatRecv" : ISODate("2016-07-24T01:35:16.014Z"
),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "localhost:27019",
                        "configVersion" : 2
                },
                {
                        "_id" : 2,
                        "name" : "localhost:27019",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 42,
                        "optime" : {
                                "ts" : Timestamp(1469324080, 1),
                                "t" : NumberLong(19)
                        },
                        "optimeDate" : ISODate("2016-07-24T01:34:40Z"),
                        "lastHeartbeat" : ISODate("2016-07-24T01:35:16.020Z"),
                        "lastHeartbeatRecv" : ISODate("2016-07-24T01:35:15.622Z"
),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "localhost:27017",
                        "configVersion" : 2
                }
        ],
        "ok" : 1
}

0 个答案:

没有答案