{"id":21889,"date":"2024-01-02T17:00:27","date_gmt":"2024-01-02T17:00:27","guid":{"rendered":"https:\/\/server.hk\/blog\/21889\/"},"modified":"2024-11-14T10:25:30","modified_gmt":"2024-11-14T02:25:30","slug":"how-to-fix-mongodb-error-code-309-exhaustcommandfinished","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21889\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-309-exhaustcommandfinished-YRyGiHqjtO\">\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished<\/h1>\n<p>MongoDB \u662f\u4e00\u6b3e\u53d7\u6b61\u8fce\u7684\u958b\u6e90 NoSQL \u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u9ad8\u6027\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u53ca\u9748\u6d3b\u6027\u3002\u7136\u800c\uff0c\u50cf\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u9047\u5230\u9700\u8981\u89e3\u6c7a\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished\u3002\u5728\u9019\u7bc7\u6587\u7ae0\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-309-exhaustcommandfinished-YRyGiHqjtO\">\u7406\u89e3 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished<\/h2>\n<p>MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished \u767c\u751f\u5728\u547d\u4ee4\u7528\u76e1\u5176\u6e38\u6a19\u4e14\u670d\u52d9\u5668\u5df2\u5b8c\u6210\u767c\u9001\u6240\u6709\u7d50\u679c\u6642\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u767c\u751f\u5728\u67e5\u8a62\u6216\u547d\u4ee4\u6aa2\u7d22\u5927\u91cf\u6587\u6a94\uff0c\u5ba2\u6236\u7aef\u5617\u8a66\u7372\u53d6\u8d85\u904e\u670d\u52d9\u5668\u80fd\u63d0\u4f9b\u7684\u7d50\u679c\u6578\u91cf\u6642\u3002<\/p>\n<p>\u7576\u6b64\u932f\u8aa4\u767c\u751f\u6642\uff0cMongoDB \u8fd4\u56de\u4e00\u500b\u985e\u4f3c\u4ee5\u4e0b\u7684\u932f\u8aa4\u6d88\u606f\uff1a<\/p>\n<p><code>Exhausted cursor, found 10000 already fetched<\/code><\/p>\n<p>\u9019\u500b\u932f\u8aa4\u6d88\u606f\u8868\u660e\u5ba2\u6236\u7aef\u5df2\u7d93\u7372\u53d6\u4e86\u670d\u52d9\u5668\u5141\u8a31\u7684\u6700\u5927\u6587\u6a94\u6578\u91cf\u3002<\/p>\n<h2 id=\"resolving-mongodb-error-code-309-exhaustcommandfinished-YRyGiHqjtO\">\u89e3\u6c7a MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished<\/h2>\n<p>\u70ba\u4e86\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished\uff0c\u4f60\u53ef\u4ee5\u63a1\u53d6\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-limit-the-number-of-documents-YRyGiHqjtO\">1. \u9650\u5236\u6587\u6a94\u6578\u91cf<\/h3>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u7372\u53d6\u5927\u91cf\u6587\u6a94\uff0c\u8acb\u8003\u616e\u9650\u5236\u67e5\u8a62\u6216\u547d\u4ee4\u8fd4\u56de\u7684\u6587\u6a94\u6578\u91cf\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>limit()<\/code> \u65b9\u6cd5\u4f86\u9650\u5236\u6aa2\u7d22\u7684\u6587\u6a94\u6578\u91cf\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>db.collection.find().limit(1000)<\/code><\/pre>\n<p>\u6b64\u67e5\u8a62\u5c07\u53ea\u8fd4\u56de\u8a72\u96c6\u5408\u7684\u524d1000\u500b\u6587\u6a94\u3002<\/p>\n<h3 id=\"2-use-pagination-YRyGiHqjtO\">2. \u4f7f\u7528\u5206\u9801<\/h3>\n<p>\u5982\u679c\u4f60\u9700\u8981\u6aa2\u7d22\u5927\u91cf\u6587\u6a94\uff0c\u8acb\u8003\u616e\u5be6\u73fe\u5206\u9801\u3002\u5206\u9801\u5141\u8a31\u4f60\u5c0f\u6279\u91cf\u7372\u53d6\u6587\u6a94\uff0c\u6e1b\u5c11\u9047\u5230 ExhaustCommandFinished \u932f\u8aa4\u7684\u53ef\u80fd\u6027\u3002\u4f60\u53ef\u4ee5\u540c\u6642\u4f7f\u7528 <code>skip()<\/code> \u548c <code>limit()<\/code> \u65b9\u6cd5\u4f86\u5be6\u65bd\u5206\u9801\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>db.collection.find().skip(1000).limit(1000)<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u5c07\u8df3\u904e\u524d1000\u500b\u6587\u6a94\u4e26\u8fd4\u56de\u8a72\u96c6\u5408\u7684\u4e0b1000\u500b\u6587\u6a94\u3002<\/p>\n<h3 id=\"3-optimize-your-query-YRyGiHqjtO\">3. \u512a\u5316\u4f60\u7684\u67e5\u8a62<\/h3>\n<p>\u6aa2\u67e5\u4f60\u7684\u67e5\u8a62\u6216\u547d\u4ee4\uff0c\u78ba\u4fdd\u5b83\u91dd\u5c0d\u6027\u80fd\u9032\u884c\u4e86\u512a\u5316\u3002\u6548\u7387\u4f4e\u4e0b\u7684\u67e5\u8a62\u53ef\u80fd\u5c0e\u81f4 ExhaustCommandFinished \u932f\u8aa4\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u6578\u64da\u96c6\u6642\u3002\u8003\u616e\u6dfb\u52a0\u9069\u7576\u7684\u7d22\u5f15\uff0c\u6709\u6548\u4f7f\u7528\u67e5\u8a62\u904b\u7b97\u7b26\uff0c\u4e26\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u64cd\u4f5c\u3002<\/p>\n<h3 id=\"4-increase-the-batch-size-YRyGiHqjtO\">4. \u589e\u52a0\u6279\u91cf\u5927\u5c0f<\/h3>\n<p>\u4f60\u53ef\u4ee5\u589e\u52a0\u6279\u91cf\u5927\u5c0f\u4ee5\u5728\u5ba2\u6236\u7aef\u8207\u670d\u52d9\u5668\u4e4b\u9593\u7684\u6bcf\u4e00\u6b21\u5f80\u8fd4\u4e2d\u7372\u53d6\u66f4\u591a\u6587\u6a94\u3002\u9ed8\u8a8d\u6279\u91cf\u5927\u5c0f\u70ba101\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>batchSize()<\/code> \u65b9\u6cd5\u4f86\u589e\u52a0\u5b83\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>db.collection.find().batchSize(1000)<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u5c07\u5728\u6bcf\u6b21\u5f80\u8fd4\u4e2d\u7372\u53d61000\u500b\u6587\u6a94\u3002<\/p>\n<h3 id=\"5-upgrade-your-mongodb-version-YRyGiHqjtO\">5. \u66f4\u65b0\u4f60\u7684 MongoDB \u7248\u672c<\/h3>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528\u8f03\u820a\u7248\u672c\u7684 MongoDB\uff0c\u8acb\u8003\u616e\u5347\u7d1a\u5230\u6700\u65b0\u7684\u7a69\u5b9a\u7248\u672c\u3002MongoDB \u5b9a\u671f\u767c\u5e03\u5305\u62ec\u932f\u8aa4\u4fee\u5fa9\u548c\u6027\u80fd\u6539\u9032\u5728\u5167\u7684\u66f4\u65b0\u3002\u5347\u7d1a\u5230\u8f03\u65b0\u7248\u672c\u53ef\u80fd\u89e3\u6c7a ExhaustCommandFinished \u932f\u8aa4\u3002<\/p>\n<h2 id=\"summary-YRyGiHqjtO\">\u6458\u8981<\/h2>\n<p>MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished \u767c\u751f\u65bc\u547d\u4ee4\u7528\u76e1\u5176\u6e38\u6a19\uff0c\u670d\u52d9\u5668\u5df2\u5b8c\u6210\u767c\u9001\u6240\u6709\u7d50\u679c\u3002\u70ba\u4e86\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u4f60\u53ef\u4ee5\u9650\u5236\u6587\u6a94\u6578\u91cf\u3001\u4f7f\u7528\u5206\u9801\u3001\u512a\u5316\u67e5\u8a62\u3001\u589e\u52a0\u6279\u91cf\u5927\u5c0f\u6216\u66f4\u65b0 MongoDB \u7248\u672c\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u9047\u5230 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 309 &#8211; ExhaustCommandFinished \u6216\u5176\u4ed6 MongoDB \u76f8\u95dc\u554f\u984c\uff0c\u8acb\u8003\u616e\u806f\u7e6b\u4e00\u500b\u53ef\u9760\u7684 VPS \u6258\u7ba1\u63d0\u4f9b\u5546\uff0c\u5982 <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u4ed6\u5011\u63d0\u4f9b\u4e00\u6d41\u7684 VPS \u89e3\u6c7a\u65b9\u6848\uff0c\u53ef\u4ee5\u5e6b\u52a9\u4f60\u512a\u5316 MongoDB \u6027\u80fd\u4e26\u78ba\u4fdd\u5e73\u7a69\u904b\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3&#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-21889","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21889","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=21889"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21889\/revisions"}],"predecessor-version":[{"id":23450,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21889\/revisions\/23450"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}