Skip to content
Advertisement

mongodb wrong members id

I’m trying to change the priority of the members of the replica set:

cfg = rs.conf();

output:

{
"_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 :

but id:3 change normaly:

cfg.members[3].priority = 0.5

0.5

what am I doing wrong? And why my version of the config too big? So many times that I couldn’t change the configuration)

Advertisement

Answer

You should address to elements of list members, not using _id property. So it will be cfg.members[0], cfg.members[1], etc

To filter by _id I think u need to use

cfg.members.filter()

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement