mongodb错误的成员id

时间:2016-12-12 20:27:09

标签: linux mongodb

我试图更改副本集成员的优先级:

  

cfg = rs.conf();

输出:

{
"_id" : "testRs",
"version" : 37747,
"protocolVersion" : NumberLong(1),
"members" : [
    {
        "_id" : 1,
        "host" : "mongo1:27017",
        "arbiterOnly" : false,
        "buildIndexes" : true,
        "hidden" : false,
        "priority" : 0.5,
        "tags" : {

        },
        "slaveDelay" : NumberLong(0),
        "votes" : 1
    },
    {
        "_id" : 3,
        "host" : "mongo2:27017",
        "arbiterOnly" : false,
        "buildIndexes" : true,
        "hidden" : false,
        "priority" : 0.5,
        "tags" : {

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

        },
        "slaveDelay" : NumberLong(0),
        "votes" : 1
    },
    {
        "_id" : 5,
        "host" : "mongo4:27017",
        "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("5800db44f99ff70bdbcdfdd9")
}

}

  

cfg.members [5] .priority = 0.5

2016-12-12T23:13:06.399+0300 E QUERY    [thread1] TypeError: cfg.members[5] is undefined :
  

cfg.members [4] .priority = 0.5

2016-12-12T23:13:17.634+0300 E QUERY    [thread1] TypeError: cfg.members[4] is undefined :

但是id:3正常改变:

  

cfg.members [3] .priority = 0.5

0.5
我做错了什么? 为什么我的配置版本太大了?这么多次,我无法改变配置)

1 个答案:

答案 0 :(得分:1)

您应该找到列表 成员 的元素,而不是使用 _id 属性。 所以它将是 cfg.members [0] cfg.members [1]

要按 _id 进行过滤,我认为你需要使用

  

cfg.members.filter()