Mongodb – Force a Member to Become Primary when Primary fails in mobgodb

failovermongodb

I have mongodb 2.6.11 cluster of two members: nms02 and nms01m. I know how to force secondary to become primary when primary is avail. But now my primary nms02 failed..and nms01m is secondary…How I force secondary to become primary now ?

nms:SECONDARY> rs.status()
{
        "set" : "nms",
        "date" : ISODate("2015-12-19T14:52:41Z"),
        "myState" : 2,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "nms02:27017",
                        "health" : 0,
                        "state" : 8,
                        "stateStr" : "(not reachable/healthy)",
                        "uptime" : 0,
                        "optime" : Timestamp(1450445883, 1),
                        "optimeDate" : ISODate("2015-12-18T13:38:03Z"),
                        "lastHeartbeat" : ISODate("2015-12-19T14:52:37Z"),
                        "lastHeartbeatRecv" : ISODate("2015-12-18T13:38:03Z"),
                        "pingMs" : 0,
                        "syncingTo" : "nms01m:27017"
                },
                {
                        "_id" : 1,
                        "name" : "nms01m:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 180204,
                        "optime" : Timestamp(1450445886, 1),
                        "optimeDate" : ISODate("2015-12-18T13:38:06Z"),
                        "self" : true
                }
        ],
        "ok" : 1
}

I can't do much on secondary now

nms:SECONDARY> cfg = rs.conf()
2015-12-19T10:20:51.821-0500 error: { "$err" : "not authorized for query on local.system.replset", "code" : 13 } at src/mongo/shell/query.js:131

Best Answer

If you have 2 members in a set, and one of them is unhealthy then you cannot elect a primary. There must be >50% (a strict majority) to elect a primary, with 1/2 nodes up you cannot satisfy that condition, you can only ever get 50% exactly, which is not sufficient. Your only option is to restore the other node or to add another node (perhaps an arbiter). However, adding a node will require a forced reconfiguration because you do not currently have a primary. Fortunately the procedure is well documented here.