Uncaught exception: TypeError: cfg.members[5] is undefined

Hi,

I am trying to change the priority of a member in a replicaset.

this is the configuration:

rs0:PRIMARY> cfg = rs.conf()
{
        "_id" : "rs0",
        "version" : 13,
        "protocolVersion" : NumberLong(1),
        "writeConcernMajorityJournalDefault" : true,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "1.6.1.103:27000",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 2,
                        "tags" : {

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

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

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

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

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

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                },
                "replicaSetId" : ObjectId("60924b04a66f63885a19d389")
        }
}

When I change member[4] configuration i have no problems:

rs0:PRIMARY> cfg.members[4].priority = 1;
1
rs0:PRIMARY> rs.reconfig(cfg)
{
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1641106224, 1),
                "signature" : {
                        "hash" : BinData(0,"flqacOlMgF7YbsFt2mMbmUDb/a4="),
                        "keyId" : NumberLong("7015948525351469087")
                }
        },
        "operationTime" : Timestamp(1641106224, 1)
}

But when I try to set member[5] configuration, I get an error:

rs0:PRIMARY> cfg.members[5].priority = 0.5;
2022-01-02T09:50:54.478+0300 E  QUERY    [js] uncaught exception: TypeError: cfg.members[5] is undefined :
@(shell):1:1

Is do see that for some reason i do not have members 2,3 defined in the resplicaset, which could be the cause for the error, but I do no understand how it came to be like this, and how can I change the priority of member 5 now.

Thanks,
Tamar

Do not use _id fro reconfigure.Use array index
Check this link:

Note : When updating the replica configuration object, access the replica set members in the members array with the array index. The array index begins with 0. Do not confuse this index value with the value of the members[n]._id field in each document in the members array.

1 Like

Thanks you @Ramachandra_Tummala
I simply then used cfg.members[3].priority = 0.5, assuming this is the array index for member with _Id 5, and it indeed changed its priority.

Tamar

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.