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
  • 1
    Having two mongod instances in a replica set is not a best approach. How did you initiate the replica set during initial configuration before fail over? Have you hard coded the priority?
    – harshavmb
    Commented Dec 19, 2015 at 19:20
  • 1
    For time being you can set the priority of secondary mongod instance greater than 1 and issue rs.reconfig(cfg) command.
    – harshavmb
    Commented Dec 19, 2015 at 19:23
  • I haven't hard coded the priority, I tried that rs.reconfig(cfg) once again and it worked . Probably forgot to login earlier..I will either drop the other db or add one more instance to have odd number of replica sets. Thnx for help
    – irom
    Commented Dec 19, 2015 at 20:01

1 Answer 1


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.

  • I'm just wondering with two mongod instances how primary was elected initially before fail over. One option is manually setting priority. Other option is forcing secondary mongod instance to never become primary. With two healthy mongod instances, election process occurs???
    – harshavmb
    Commented Dec 20, 2015 at 2:35
  • 1
    With 2 healthy instances you get 2/2 votes for one of the nodes, and then that node is elected primary, with 2/2 satisfying the >50% rule. If either node goes down you cannot have a primary in that set (regardless of priority settings) until you bring the bad node back up or reconfigure the set. This, and the associated greater risk of failure, is why a 2 node set is not a recommended configuration.
    – Adam C
    Commented Dec 20, 2015 at 14:50
  • Got it! Thanks for your clarification. Was thinking that with two nodes, election process never happen as there would be 50-50 chances .. Now I got it!
    – harshavmb
    Commented Dec 20, 2015 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.