Changing rs config in mongodb

As root: connect to mongo

MongoDB shell version: 2.0.1
connecting to: test
--show rs configuration for the server group PRIMARY> cfg = rs.conf() { "_id" : "repperfmongo", "version" : 3, "members" : [
                {
                        "_id" : 0,
                        "host" : "perf.domain.net:27017",
                        "priority" : 10
                },
                {
                        "_id" : 1,
                        "host" : "perf.domain.net:27017",
                        "priority" : 5
                },
                {
                        "_id" : 2,
                        "host" : "perf.domain.net:27017",
                        "priority" : 0,
                        "slaveDelay" : 3600
                }
        ]
}

For example, to change the slavedelay on the third node (member 2)

-- this makes the change. the property is case sensitive PRIMARY> cfg.members[2].slaveDelay = 0
0
-- this confirms the change PRIMARY> rs.reconfig(cfg) { "ok" : 1 } PRIMARY> cfg = rs.conf() { "_id" : "repperfmongo", "version" : 4, "members" : [
                {
                        "_id" : 0,
                        "host" : "perf.domain.net:27017",
                        "priority" : 10
                },
                {
                        "_id" : 1,
                        "host" : "perf.domain.net:27017",
                        "priority" : 5
                },
                {
                        "_id" : 2,
                        "host" : "perf.domain.net:27017",
                        "priority" : 0
                }
        ]
}

To change the priority of a member:

-- change the priority of member 2 PRIMARY> cfg.members[2].priority = 5
5
-- confirm the change PRIMARY> rs.reconfig(cfg) { "ok" : 1 } -- show new config PRIMARY> cfg = rs.conf() { "_id" : "repperfmongo", "version" : 5, "members" : [
                {
                        "_id" : 0,
                        "host" : "perf.domain.net:27017",
                        "priority" : 10
                },
                {
                        "_id" : 1,
                        "host" : "perf.domain.net:27017",
                        "priority" : 5
                },
                {
                        "_id" : 2,
                        "host" : "perf.domain.net:27017",
                        "priority" : 5
                }
        ]
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: