{"id":21799,"date":"2024-01-02T15:30:27","date_gmt":"2024-01-02T15:30:27","guid":{"rendered":"https:\/\/server.hk\/blog\/21799\/"},"modified":"2024-11-14T10:26:51","modified_gmt":"2024-11-14T02:26:51","slug":"how-to-fix-mongodb-error-code-216-electioninprogress","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21799\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9MongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-216-electioninprogress-vEGfxjgXKH\">\u5982\u4f55\u4fee\u5fa9MongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress<\/h1>\n<p>MongoDB\u662f\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90NoSQL\u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u9ad8\u6027\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u53ca\u9748\u6d3b\u6027\u3002\u7136\u800c\uff0c\u5c31\u50cf\u5176\u4ed6\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u9700\u8981\u89e3\u6c7a\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e4b\u4e00\u662fMongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u9019\u500b\u932f\u8aa4\u7684\u542b\u7fa9\u4ee5\u53ca\u5982\u4f55\u4fee\u5fa9\u5b83\u3002<\/p>\n<h2 id=\"understanding-mongodb-error-code-216-electioninprogress-vEGfxjgXKH\">\u4e86\u89e3MongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress<\/h2>\n<p>MongoDB\u4f7f\u7528\u7a31\u70ba\u526f\u672c\u96c6\u7684\u5206\u4f48\u5f0f\u67b6\u69cb\u4f86\u78ba\u4fdd\u9ad8\u53ef\u7528\u6027\u548c\u6578\u64da\u5197\u9918\u3002\u4e00\u500b\u526f\u672c\u96c6\u5305\u62ec\u591a\u500bMongoDB\u5be6\u4f8b\uff0c\u5176\u4e2d\u4e00\u500b\u5145\u7576\u4e3b\u7bc0\u9ede\uff0c\u5176\u4ed6\u4f5c\u70ba\u6b21\u7d1a\u7bc0\u9ede\u3002\u4e3b\u7bc0\u9ede\u8655\u7406\u6240\u6709\u5beb\u64cd\u4f5c\uff0c\u800c\u6b21\u7d1a\u7bc0\u9ede\u5247\u5f9e\u4e3b\u7bc0\u9ede\u8907\u88fd\u6578\u64da\u3002<\/p>\n<p>\u5728\u67d0\u4e9b\u4e8b\u4ef6\uff0c\u5982\u7db2\u7d61\u5206\u5272\u6216\u4e3b\u7bc0\u9ede\u5931\u6557\u6642\uff0cMongoDB\u6703\u555f\u52d5\u4e00\u500b\u9078\u8209\u904e\u7a0b\u4f86\u9078\u64c7\u65b0\u7684\u4e3b\u7bc0\u9ede\u3002\u9019\u500b\u904e\u7a0b\u88ab\u7a31\u70ba\u9078\u8209\u3002\u7576\u9078\u8209\u5df2\u5728\u9032\u884c\u4e2d\uff0c\u800c\u5617\u8a66\u9032\u884c\u53e6\u4e00\u500b\u9078\u8209\u6642\uff0c\u5c31\u6703\u767c\u751fMongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress\u3002<\/p>\n<h2 id=\"causes-of-mongodb-error-code-216-electioninprogress-vEGfxjgXKH\">MongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress\u7684\u539f\u56e0<\/h2>\n<p>\u60a8\u53ef\u80fd\u6703\u9047\u5230\u6b64\u932f\u8aa4\u7684\u5e7e\u500b\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u7db2\u7d61\u554f\u984c\uff1a<\/strong>\u7bc0\u9ede\u9593\u7684\u7db2\u7d61\u5206\u5272\u6216\u9023\u63a5\u554f\u984c\u53ef\u89f8\u767c\u9078\u8209\u904e\u7a0b\u3002\u5982\u679c\u7db2\u7d61\u554f\u984c\u6301\u7e8c\uff0c\u5247\u53ef\u5c0e\u81f4\u591a\u6b21\u9078\u8209\u5617\u8a66\u3002<\/li>\n<li><strong>\u786c\u4ef6\u6216\u670d\u52d9\u5668\u6545\u969c\uff1a<\/strong>\u5982\u679c\u4e3b\u7bc0\u9ede\u5931\u6557\u6216\u7d93\u6b77\u786c\u4ef6\u554f\u984c\uff0cMongoDB\u6703\u89f8\u767c\u9078\u8209\u4f86\u9078\u64c7\u65b0\u7684\u4e3b\u7bc0\u9ede\u3002\u5982\u679c\u5931\u6557\u662f\u9593\u6b47\u6027\u7684\u6216\u672a\u89e3\u6c7a\uff0c\u5247\u53ef\u5c0e\u81f4\u91cd\u8907\u7684\u9078\u8209\u5617\u8a66\u3002<\/li>\n<li><strong>\u914d\u7f6e\u554f\u984c\uff1a<\/strong>\u4e0d\u6b63\u78ba\u7684\u914d\u7f6e\u8a2d\u5b9a\uff0c\u5982\u932f\u8aa4\u7684\u526f\u672c\u96c6\u540d\u7a31\u6216\u4e3b\u6a5f\u540d\u7a31\/IP\u5730\u5740\uff0c\u53ef\u5c0e\u81f4\u91cd\u8907\u7684\u9078\u8209\u5617\u8a66\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-mongodb-error-code-216-electioninprogress-vEGfxjgXKH\">\u4fee\u5fa9MongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress<\/h2>\n<p>\u8981\u89e3\u6c7aMongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress\uff0c\u8acb\u9075\u5faa\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"step-1-identify-the-primary-node-vEGfxjgXKH\">\u6b65\u9a5f 1\uff1a\u8b58\u5225\u4e3b\u7bc0\u9ede<\/h3>\n<p>\u4f7f\u7528MongoDB shell\u6216MongoDB\u5ba2\u6236\u7aef\u9023\u63a5\u5230\u526f\u672c\u96c6\u4e2d\u7684\u4e00\u500bMongoDB\u5be6\u4f8b\u3002\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u8b58\u5225\u4e3b\u7bc0\u9ede\uff1a<\/p>\n<p><code>rs.isMaster()<\/code><\/p>\n<p>\u8f38\u51fa\u5c07\u5305\u62ec\u6709\u95dc\u526f\u672c\u96c6\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u4e3b\u7bc0\u9ede\u7684\u4e3b\u6a5f\u540d\u7a31\u6216IP\u5730\u5740\u3002<\/p>\n<h3 id=\"step-2-check-network-connectivity-vEGfxjgXKH\">\u6b65\u9a5f 2\uff1a\u6aa2\u67e5\u7db2\u7d61\u9023\u63a5\u6027<\/h3>\n<p>\u78ba\u4fdd\u526f\u672c\u96c6\u4e2d\u6240\u6709\u7bc0\u9ede\u80fd\u5920\u5f7c\u6b64\u901a\u8a0a\u3002\u6aa2\u67e5\u4efb\u4f55\u7db2\u7d61\u554f\u984c\uff0c\u5982\u963b\u64cbMongoDB\u6d41\u91cf\u7684\u9632\u706b\u7246\u6216\u7db2\u7d61\u5206\u5272\u3002\u89e3\u6c7a\u4efb\u4f55\u9023\u63a5\u554f\u984c\u4ee5\u9632\u6b62\u91cd\u8907\u7684\u9078\u8209\u5617\u8a66\u3002<\/p>\n<h3 id=\"step-3-verify-replica-set-configuration-vEGfxjgXKH\">\u6b65\u9a5f 3\uff1a\u9a57\u8b49\u526f\u672c\u96c6\u914d\u7f6e<\/h3>\n<p>\u6aa2\u67e5\u526f\u672c\u96c6\u914d\u7f6e\u4ee5\u78ba\u4fdd\u6b63\u78ba\u8a2d\u7f6e\u3002\u5728MongoDB shell\u4e2d\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<p><code>rs.conf()<\/code><\/p>\n<p>\u9a57\u8b49\u526f\u672c\u96c6\u540d\u7a31\u548c\u6240\u6709\u7bc0\u9ede\u7684\u4e3b\u6a5f\u540d\u7a31\/IP\u5730\u5740\u662f\u5426\u6e96\u78ba\u3002\u5982\u679c\u767c\u73fe\u4efb\u4f55\u914d\u7f6e\u554f\u984c\uff0c\u8acb\u4f7f\u7528<code>rs.reconfig()<\/code>\u547d\u4ee4\u9032\u884c\u66f4\u65b0\u3002<\/p>\n<h3 id=\"step-4-restart-mongodb-instances-vEGfxjgXKH\">\u6b65\u9a5f 4\uff1a\u91cd\u555fMongoDB\u5be6\u4f8b<\/h3>\n<p>\u5982\u679c\u932f\u8aa4\u6301\u7e8c\u5b58\u5728\uff0c\u8acb\u5617\u8a66\u91cd\u555f\u526f\u672c\u96c6\u4e2d\u7684\u6240\u6709MongoDB\u5be6\u4f8b\u3002\u9996\u5148\u91cd\u555f\u6b21\u7d1a\u7bc0\u9ede\uff0c\u7136\u5f8c\u91cd\u555f\u4e3b\u7bc0\u9ede\u3002\u9019\u53ef\u4ee5\u5e6b\u52a9\u89e3\u6c7a\u5c0e\u81f4\u91cd\u8907\u9078\u8209\u5617\u8a66\u7684\u4efb\u4f55\u81e8\u6642\u554f\u984c\u3002<\/p>\n<h3 id=\"step-5-monitor-the-replica-set-vEGfxjgXKH\">\u6b65\u9a5f 5\uff1a\u76e3\u63a7\u526f\u672c\u96c6<\/h3>\n<p>\u5be6\u65bd\u4ee5\u4e0a\u6b65\u9a5f\u5f8c\uff0c\u76e3\u63a7\u526f\u672c\u96c6\u662f\u5426\u518d\u6b21\u51fa\u73feMongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress\u3002\u5bc6\u5207\u7559\u610fMongoDB\u65e5\u8a8c\uff0c\u6aa2\u67e5\u4efb\u4f55\u7570\u5e38\u884c\u70ba\u6216\u932f\u8aa4\u4fe1\u606f\u3002<\/p>\n<h2 id=\"summary-vEGfxjgXKH\">\u7e3d\u7d50<\/h2>\n<p>MongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress\u767c\u751f\u5728\u526f\u672c\u96c6\u4e2d\u9032\u884c\u591a\u6b21\u9078\u8209\u5617\u8a66\u6642\u3002\u6b64\u932f\u8aa4\u53ef\u80fd\u7531\u7db2\u7d61\u554f\u984c\u3001\u786c\u4ef6\u6545\u969c\u6216\u914d\u7f6e\u554f\u984c\u5f15\u8d77\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u8b58\u5225\u4e3b\u7bc0\u9ede\uff0c\u6aa2\u67e5\u7db2\u7d61\u9023\u63a5\u6027\uff0c\u9a57\u8b49\u526f\u672c\u96c6\u914d\u7f6e\uff0c\u91cd\u555fMongoDB\u5be6\u4f8b\uff0c\u4e26\u76e3\u63a7\u526f\u672c\u96c6\u662f\u5426\u518d\u6b21\u767c\u751f\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9047\u5230MongoDB\u932f\u8aa4\u78bc &#8211; 216 &#8211; ElectionInProgress\u6216\u4efb\u4f55\u5176\u4ed6MongoDB\u76f8\u95dc\u554f\u984c\uff0c\u8acb\u8003\u616e\u806f\u7e6b<a href=\"https:\/\/server.hk\">Server.HK<\/a>\u9019\u6a23\u7684\u53ef\u9760VPS\u4e3b\u6a5f\u63d0\u4f9b\u8005\u3002\u4ed6\u5011\u63d0\u4f9b\u9802\u7d1a\u7684VPS\u89e3\u6c7a\u65b9\u6848\uff0c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u512a\u5316MongoDB\u90e8\u7f72\uff0c\u4e26\u78ba\u4fdd\u5e73\u7a69\u904b\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9MongoDB\u932f\u8aa4\u78bc &#038;&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-21799","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=21799"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21799\/revisions"}],"predecessor-version":[{"id":23567,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21799\/revisions\/23567"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}