Table of Contents

Overview

Replica configuration can be changed fairly easy. The steps to do that are:

  1. Save Configuration
  2. Edit configuration
  3. Enable Configuration

Simple as that:

Save the configuration

[root@lparamongo mongo]# mongo --port 9005
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:9005/test
testset:PRIMARY> rs.status()
{
        "set" : "testset",
        "date" : ISODate("2018-03-24T22:07:37Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "lparamongo:9005",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 2172,
                        "optime" : Timestamp(1521929109, 1),
                        "optimeDate" : ISODate("2018-03-24T22:05:09Z"),
                        "electionTime" : Timestamp(1521927136, 2),
                        "electionDate" : ISODate("2018-03-24T21:32:16Z"),
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "lparbmongo:9005",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 1914,
                        "optime" : Timestamp(1521929109, 1),
                        "optimeDate" : ISODate("2018-03-24T22:05:09Z"),
                        "lastHeartbeat" : ISODate("2018-03-24T22:07:36Z"),
                        "lastHeartbeatRecv" : ISODate("2018-03-24T22:07:35Z"),
                        "pingMs" : 0,
                        "syncingTo" : "lparamongo:9005"
                },
                {
                        "_id" : 2,
                        "name" : "lparcmongo:9005",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 148,
                        "optime" : Timestamp(1521929109, 1),
                        "optimeDate" : ISODate("2018-03-24T22:05:09Z"),
                        "lastHeartbeat" : ISODate("2018-03-24T22:07:35Z"),
                        "lastHeartbeatRecv" : ISODate("2018-03-24T22:07:36Z"),
                        "pingMs" : 0,
                        "syncingTo" : "lparamongo:9005"
                }
        ],
        "ok" : 1
}
testset:PRIMARY> conf = rs.conf()
{
        "_id" : "testset",
        "version" : 3,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "lparamongo:9005"
                },
                {
                        "_id" : 1,
                        "host" : "lparbmongo:9005"
                },
                {
                        "_id" : 2,
                        "host" : "lparcmongo:9005"
                }
        ]
}

Reconfigure the target member

testset:PRIMARY> conf.members[2].hidden=true
true
testset:PRIMARY> conf.members[2].priority=0
0
testset:PRIMARY> conf
{
        "_id" : "testset",
        "version" : 3,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "lparamongo:9005"
                },
                {
                        "_id" : 1,
                        "host" : "lparbmongo:9005"
                },
                {
                        "_id" : 2,
                        "host" : "lparcmongo:9005",
                        "hidden" : true,
                        "priority" : 0
                }
        ]
}
testset:PRIMARY>

This reconfiguration, put the 3rd member in hidden and with priority (0) meaning that:

  1. lparacmongo is passive node
  2. He cannot become primary

Enable Configuration

To enable configuration, simple issue the following command on the primary:

testset:PRIMARY> rs.reconfig(conf)
2018-03-24T23:20:07.513+0100 DBClientCursor::init call() failed
2018-03-24T23:20:07.515+0100 trying reconnect to 127.0.0.1:9005 (127.0.0.1) failed
2018-03-24T23:20:07.515+0100 reconnect 127.0.0.1:9005 (127.0.0.1) ok
reconnected to server after rs command (which is normal)

testset:PRIMARY> rs.status()
{
        "set" : "testset",
        "date" : ISODate("2018-03-24T22:20:14Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "lparamongo:9005",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 2929,
                        "optime" : Timestamp(1521930007, 1),
                        "optimeDate" : ISODate("2018-03-24T22:20:07Z"),
                        "electionTime" : Timestamp(1521927136, 2),
                        "electionDate" : ISODate("2018-03-24T21:32:16Z"),
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "lparbmongo:9005",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 7,
                        "optime" : Timestamp(1521930007, 1),
                        "optimeDate" : ISODate("2018-03-24T22:20:07Z"),
                        "lastHeartbeat" : ISODate("2018-03-24T22:20:13Z"),
                        "lastHeartbeatRecv" : ISODate("2018-03-24T22:20:13Z"),
                        "pingMs" : 0,
                        "lastHeartbeatMessage" : "syncing to: lparamongo:9005",
                        "syncingTo" : "lparamongo:9005"
                },
                {
                        "_id" : 2,
                        "name" : "lparcmongo:9005",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 7,
                        "optime" : Timestamp(1521930007, 1),
                        "optimeDate" : ISODate("2018-03-24T22:20:07Z"),
                        "lastHeartbeat" : ISODate("2018-03-24T22:20:13Z"),
                        "lastHeartbeatRecv" : ISODate("2018-03-24T22:20:12Z"),
                        "pingMs" : 0,
                        "lastHeartbeatMessage" : "syncing to: lparamongo:9005",
                        "syncingTo" : "lparamongo:9005"
                }
        ],
        "ok" : 1
}
testset:PRIMARY>

After the sync has been done, you should receive a normal hearthbeat message:

testset:PRIMARY> rs.status()
{
        "set" : "testset",
        "date" : ISODate("2018-03-24T22:23:07Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "lparamongo:9005",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 3102,
                        "optime" : Timestamp(1521930007, 1),
                        "optimeDate" : ISODate("2018-03-24T22:20:07Z"),
                        "electionTime" : Timestamp(1521927136, 2),
                        "electionDate" : ISODate("2018-03-24T21:32:16Z"),
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "lparbmongo:9005",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 180,
                        "optime" : Timestamp(1521930007, 1),
                        "optimeDate" : ISODate("2018-03-24T22:20:07Z"),
                        "lastHeartbeat" : ISODate("2018-03-24T22:23:07Z"),
                        "lastHeartbeatRecv" : ISODate("2018-03-24T22:23:07Z"),
                        "pingMs" : 0,
                        "syncingTo" : "lparamongo:9005"
                },
                {
                        "_id" : 2,
                        "name" : "lparcmongo:9005",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 180,
                        "optime" : Timestamp(1521930007, 1),
                        "optimeDate" : ISODate("2018-03-24T22:20:07Z"),
                        "lastHeartbeat" : ISODate("2018-03-24T22:23:07Z"),
                        "lastHeartbeatRecv" : ISODate("2018-03-24T22:23:06Z"),
                        "pingMs" : 0,
                        "syncingTo" : "lparamongo:9005"
                }
        ],
        "ok" : 1
}