{"id":21822,"date":"2024-01-02T15:53:25","date_gmt":"2024-01-02T15:53:25","guid":{"rendered":"https:\/\/server.hk\/blog\/21822\/"},"modified":"2024-11-14T10:26:30","modified_gmt":"2024-11-14T02:26:30","slug":"how-to-fix-mongodb-error-code-239-snapshottooold","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21822\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u78bc &#8211; 239 &#8211; SnapshotTooOld"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-239-snapshottooold-VlSgITIpvj\">\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u78bc &#8211; 239 &#8211; SnapshotTooOld<\/h1>\n<p>MongoDB \u662f\u4e00\u500b\u53d7\u6b61\u8fce\u7684 NoSQL \u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u9ad8\u6027\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u548c\u9748\u6d3b\u6027\u3002\u7136\u800c\uff0c\u8207\u5176\u4ed6\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u53ef\u80fd\u6703\u5f71\u97ff\u5176\u6b63\u5e38\u904b\u4f5c\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f MongoDB \u932f\u8aa4\u78bc &#8211; 239 &#8211; SnapshotTooOld\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-239-snapshottooold-VlSgITIpvj\">\u4e86\u89e3 MongoDB \u932f\u8aa4\u78bc &#8211; 239 &#8211; SnapshotTooOld<\/h2>\n<p>\u5728\u4f7f\u7528 MongoDB \u6642\uff0c\u60a8\u53ef\u80fd\u9047\u5230\u932f\u8aa4\u6d88\u606f\u300cSnapshotTooOld\u300d\u4ee5\u53ca\u932f\u8aa4\u78bc 239\u3002\u6b64\u932f\u8aa4\u767c\u751f\u5728\u8b80\u53d6\u64cd\u4f5c\u7121\u6cd5\u627e\u5230\u4e00\u81f4\u7684\u6578\u64da\u5feb\u7167\uff0c\u539f\u56e0\u662f\u5728\u8b80\u53d6\u904e\u7a0b\u4e2d\u6578\u64da\u88ab\u4fee\u6539\u3002<\/p>\n<p>\u7576 MongoDB \u57f7\u884c\u8b80\u53d6\u64cd\u4f5c\u6642\uff0c\u5b83\u4f7f\u7528\u6578\u64da\u7684\u5feb\u7167\u4f86\u78ba\u4fdd\u4e00\u81f4\u6027\u3002\u7136\u800c\uff0c\u5982\u679c\u5728\u8b80\u53d6\u64cd\u4f5c\u9032\u884c\u6642\u6578\u64da\u88ab\u4fee\u6539\uff0c\u5feb\u7167\u5c31\u6703\u8b8a\u5f97\u904e\u6642\uff0c\u5f9e\u800c\u5c0e\u81f4 SnapshotTooOld \u932f\u8aa4\u3002<\/p>\n<h2 id=\"causes-of-snapshottooold-error-VlSgITIpvj\">SnapshotTooOld \u932f\u8aa4\u7684\u539f\u56e0<\/h2>\n<p>\u5728 MongoDB \u4e2d\uff0c\u60a8\u53ef\u80fd\u9047\u5230 SnapshotTooOld \u932f\u8aa4\u7684\u539f\u56e0\u6709\u5e7e\u500b\uff1a<\/p>\n<ul>\n<li><strong>\u9577\u6642\u9593\u904b\u884c\u7684\u4ea4\u6613\uff1a<\/strong> \u5982\u679c\u60a8\u6709\u9577\u6642\u9593\u904b\u884c\u7684\u4ea4\u6613\u5728\u8b80\u53d6\u64cd\u4f5c\u9032\u884c\u6642\u4fee\u6539\u6578\u64da\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u6b64\u932f\u8aa4\u3002<\/li>\n<li><strong>\u9ad8\u5beb\u5165\u541e\u5410\u91cf\uff1a<\/strong> \u5982\u679c\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u57f7\u884c\u5927\u91cf\u7684\u5beb\u5165\u64cd\u4f5c\uff0c\u589e\u52a0\u4e86\u9047\u5230\u6b64\u932f\u8aa4\u7684\u53ef\u80fd\u6027\u3002<\/li>\n<li><strong>\u5167\u5b58\u4e0d\u8db3\uff1a<\/strong> \u5982\u679c\u60a8\u7684 MongoDB \u4f3a\u670d\u5668\u5167\u5b58\u4e0d\u8db3\u4ee5\u6709\u6548\u8655\u7406\u8b80\u53d6\u548c\u5beb\u5165\u64cd\u4f5c\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u4e0d\u4e00\u81f4\u7684\u5feb\u7167\u4e26\u89f8\u767c\u6b64\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-the-snapshottooold-error-VlSgITIpvj\">\u4fee\u5fa9 SnapshotTooOld \u932f\u8aa4<\/h2>\n<p>\u8981\u4fee\u5fa9 MongoDB \u4e2d\u7684 SnapshotTooOld \u932f\u8aa4\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<h3 id=\"1-optimize-your-queries-VlSgITIpvj\">1. \u512a\u5316\u60a8\u7684\u67e5\u8a62<\/h3>\n<p>\u6aa2\u67e5\u60a8\u7684\u67e5\u8a62\u4e26\u78ba\u4fdd\u5b83\u5011\u662f\u6709\u6548\u7684\u3002\u6548\u7387\u4f4e\u4e0b\u7684\u67e5\u8a62\u53ef\u80fd\u6703\u589e\u52a0\u9047\u5230\u6b64\u932f\u8aa4\u7684\u53ef\u80fd\u6027\u3002\u4f7f\u7528 MongoDB \u7684\u67e5\u8a62\u512a\u5316\u6280\u8853\uff0c\u5982\u5275\u5efa\u7d22\u5f15\u3001\u4f7f\u7528\u8986\u84cb\u67e5\u8a62\u548c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u6578\u64da\u6aa2\u7d22\u3002<\/p>\n<h3 id=\"2-increase-the-oplog-size-VlSgITIpvj\">2. \u589e\u52a0 oplog \u5927\u5c0f<\/h3>\n<p>oplog\uff08\u64cd\u4f5c\u65e5\u8a8c\uff09\u662f MongoDB \u4e2d\u8a18\u9304\u6240\u6709\u5beb\u5165\u64cd\u4f5c\u7684\u6709\u4e0a\u9650\u96c6\u5408\u3002\u901a\u904e\u589e\u52a0 oplog \u5927\u5c0f\uff0c\u60a8\u53ef\u4ee5\u70ba MongoDB \u63d0\u4f9b\u66f4\u591a\u7684\u7a7a\u9593\u4f86\u5b58\u5132\u5beb\u5165\u64cd\u4f5c\uff0c\u5f9e\u800c\u6e1b\u5c11\u9047\u5230 SnapshotTooOld \u932f\u8aa4\u7684\u6a5f\u6703\u3002\u60a8\u53ef\u4ee5\u6309\u7167 MongoDB \u7684\u6587\u6a94\u4fee\u6539 oplog \u5927\u5c0f\u3002<\/p>\n<h3 id=\"3-add-more-memory-VlSgITIpvj\">3. \u589e\u52a0\u5167\u5b58<\/h3>\n<p>\u5982\u679c\u60a8\u7684 MongoDB \u4f3a\u670d\u5668\u5167\u5b58\u4e0d\u8db3\uff0c\u53ef\u4ee5\u8003\u616e\u589e\u52a0\u5167\u5b58\u4ee5\u6539\u5584\u5176\u6027\u80fd\u3002\u5145\u8db3\u7684\u5167\u5b58\u8b93 MongoDB \u80fd\u5920\u66f4\u6709\u6548\u5730\u8655\u7406\u8b80\u53d6\u548c\u5beb\u5165\u64cd\u4f5c\uff0c\u6e1b\u5c11\u9047\u5230\u6b64\u932f\u8aa4\u7684\u6a5f\u6703\u3002<\/p>\n<h3 id=\"4-implement-sharding-VlSgITIpvj\">4. \u5be6\u65bd\u5206\u7247<\/h3>\n<p>\u5982\u679c\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u5177\u6709\u9ad8\u5beb\u5165\u541e\u5410\u91cf\uff0c\u5be6\u65bd\u5206\u7247\u53ef\u4ee5\u5c07\u5beb\u5165\u8ca0\u8f09\u5206\u6563\u5230\u591a\u500b\u5206\u7247\uff0c\u5f9e\u800c\u6e1b\u5c11\u9047\u5230 SnapshotTooOld \u932f\u8aa4\u7684\u6a5f\u6703\u3002\u5206\u7247\u4f7f MongoDB \u80fd\u5920\u6c34\u5e73\u64f4\u5c55\u4e26\u8655\u7406\u66f4\u5927\u91cf\u7684\u5beb\u5165\u64cd\u4f5c\u3002<\/p>\n<h3 id=\"5-upgrade-mongodb-VlSgITIpvj\">5. \u5347\u7d1a MongoDB<\/h3>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u8f03\u820a\u7248\u672c\u7684 MongoDB\uff0c\u53ef\u4ee5\u8003\u616e\u5347\u7d1a\u5230\u6700\u65b0\u7684\u7a69\u5b9a\u7248\u672c\u3002MongoDB \u5b9a\u671f\u767c\u5e03\u5e36\u6709\u932f\u8aa4\u4fee\u5fa9\u548c\u6027\u80fd\u6539\u9032\u7684\u66f4\u65b0\uff0c\u6709\u52a9\u65bc\u6e1b\u8f15 SnapshotTooOld \u932f\u8aa4\u5e36\u4f86\u7684\u554f\u984c\u3002<\/p>\n<h2 id=\"summary-VlSgITIpvj\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u800c\u8a00\u4e4b\uff0c\u5728 MongoDB \u4e2d\uff0cSnapshotTooOld \u932f\u8aa4\u53ef\u80fd\u5728\u8b80\u53d6\u64cd\u4f5c\u7121\u6cd5\u627e\u5230\u4e00\u81f4\u7684\u6578\u64da\u5feb\u7167\uff0c\u539f\u56e0\u662f\u5728\u8b80\u53d6\u904e\u7a0b\u4e2d\u6578\u64da\u88ab\u4fee\u6539\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u53ef\u4ee5\u512a\u5316\u60a8\u7684\u67e5\u8a62\u3001\u589e\u52a0 oplog \u5927\u5c0f\u3001\u589e\u52a0\u5167\u5b58\u3001\u5be6\u65bd\u5206\u7247\uff0c\u4e26\u8003\u616e\u5347\u7d1a\u81f3\u6700\u65b0\u7248\u672c\u7684 MongoDB\u3002\u5982\u679c\u60a8\u9047\u5230\u6b64\u932f\u8aa4\uff0cServer.HK \u63d0\u4f9b\u53ef\u9760\u548c\u9ad8\u6027\u80fd\u7684 VPS \u4e3b\u6a5f\u65b9\u6848\uff0c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u512a\u5316 MongoDB \u90e8\u7f72\u3002\u8acb\u806f\u7e6b\u6211\u5011\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u78bc&#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-21822","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21822","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=21822"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21822\/revisions"}],"predecessor-version":[{"id":23535,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21822\/revisions\/23535"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}