mongo副本集 - 数据不复制

时间:2016-07-21 19:57:00

标签: mongodb

我在单个节点上使用mongo v3.2设置了测试replcia集,而mongo shell中的rs.status()命令似乎表明副本集已建立(下面的输出)。

但是,当我将数据插入主数据库时,我可以看到它被插入到主数据库中,但我似乎无法在任何辅助进程上运行查找操作(下面给出的消息)

次要消息

消息

Error: error: { "ok" : 0, "errmsg" : "not master and slaveOk=false", "code" : 13435 }

rs.status()

{
    "set" : "set0",
    "date" : ISODate("2016-07-21T19:53:41.882Z"),
    "myState" : 1,
    "term" : NumberLong(1),
    "heartbeatIntervalMillis" : NumberLong(2000),
    "members" : [
        {
            "_id" : 0,
            "name" : "127.0.0.1:27049",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 2388,
            "optime" : {
                "ts" : Timestamp(1469130790, 2),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-07-21T19:53:10Z"),
            "electionTime" : Timestamp(1469128700, 1),
            "electionDate" : ISODate("2016-07-21T19:18:20Z"),
            "configVersion" : 1,
            "self" : true
        },
        {
            "_id" : 1,
            "name" : "127.0.0.1:27050",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 2132,
            "optime" : {
                "ts" : Timestamp(1469130790, 2),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-07-21T19:53:10Z"),
            "lastHeartbeat" : ISODate("2016-07-21T19:53:40.964Z"),
            "lastHeartbeatRecv" : ISODate("2016-07-21T19:53:40.823Z"),
            "pingMs" : NumberLong(0),
            "syncingTo" : "127.0.0.1:27049",
            "configVersion" : 1
        },
        {
            "_id" : 2,
            "name" : "127.0.0.1:27051",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 2132,
            "optime" : {
                "ts" : Timestamp(1469130790, 2),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2016-07-21T19:53:10Z"),
            "lastHeartbeat" : ISODate("2016-07-21T19:53:40.963Z"),
            "lastHeartbeatRecv" : ISODate("2016-07-21T19:53:40.823Z"),
            "pingMs" : NumberLong(0),
            "syncingTo" : "127.0.0.1:27049",
            "configVersion" : 1
        }
    ],
    "ok" : 1
}

主要

上的rs.conf()输出
{
    "_id" : "set0",
    "version" : 1,
    "protocolVersion" : NumberLong(1),
    "members" : [
        {
            "_id" : 0,
            "host" : "127.0.0.1:27049",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        },
        {
            "_id" : 1,
            "host" : "127.0.0.1:27050",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        },
        {
            "_id" : 2,
            "host" : "127.0.0.1:27051",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : NumberLong(0),
            "votes" : 1
        }
    ],
    "settings" : {
        "chainingAllowed" : true,
        "heartbeatIntervalMillis" : 2000,
        "heartbeatTimeoutSecs" : 10,
        "electionTimeoutMillis" : 10000,
        "getLastErrorModes" : {

        },
        "getLastErrorDefaults" : {
            "w" : 1,
            "wtimeout" : 0
        },
        "replicaSetId" : ObjectId("57911ff0bd131f1aeb2ef878")
    }
}

1 个答案:

答案 0 :(得分:0)

在辅助进程上运行以下命令后,我能够从辅助进程读取数据:

cursor.execute('''CREATE TABLE (?)(id INTEGER, Topics TEXT)''', (str(nameTable)))
sqlite3.OperationalError: near "(": syntax error

rs.slaveOk() 

从Mongo shell运行以下命令后,我可以使用find命令从Mongo获取所需的文档。