{"id":21638,"date":"2024-01-02T12:49:24","date_gmt":"2024-01-02T12:49:24","guid":{"rendered":"https:\/\/server.hk\/blog\/21638\/"},"modified":"2024-11-14T10:29:24","modified_gmt":"2024-11-14T02:29:24","slug":"how-to-fix-mongodb-error-code-43-cursornotfound","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21638\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-43-cursornotfound-OkkZBhyVFE\">\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound<\/h1>\n<p>MongoDB \u662f\u4e00\u6b3e\u6d41\u884c\u7684 NoSQL \u6578\u64da\u5eab\uff0c\u5177\u5099\u9ad8\u6548\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u548c\u9748\u6d3b\u6027\u3002\u7136\u800c\uff0c\u50cf\u5176\u4ed6\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u4e5f\u53ef\u80fd\u9047\u5230\u9700\u8981\u89e3\u6c7a\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e4b\u4e00\u5c31\u662f MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound\u3002\u672c\u6587\u5c07\u6df1\u5165\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-43-cursornotfound-OkkZBhyVFE\">\u7406\u89e3 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound<\/h2>\n<p>\u7576\u5ba2\u6236\u7aef\u8a66\u5716\u8a2a\u554f\u7684\u6e38\u6a19\u4e0d\u518d\u53ef\u7528\u65bc\u4f3a\u670d\u5668\u6642\uff0c\u5c31\u6703\u767c\u751f MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound\u3002\u6e38\u6a19\u662f\u4e00\u500b\u6307\u5411\u67e5\u8a62\u7d50\u679c\u96c6\u7684\u6307\u6a19\uff0c\u8b93\u5ba2\u6236\u7aef\u80fd\u5920\u6279\u91cf\u6aa2\u7d22\u6587\u6a94\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u662f\u5728\u6e38\u6a19\u8d85\u6642\u6216\u88ab\u4f3a\u670d\u5668\u95dc\u9589\u6642\u51fa\u73fe\u7684\u3002<\/p>\n<h2 id=\"causes-of-mongodb-error-code-43-cursornotfound-OkkZBhyVFE\">MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound \u7684\u6210\u56e0<\/h2>\n<p>\u60a8\u53ef\u80fd\u6703\u9047\u5230\u6b64\u932f\u8aa4\u7684\u539f\u56e0\u6709\u5e7e\u500b\uff1a<\/p>\n<ul>\n<li><strong>\u6e38\u6a19\u8d85\u6642\uff1a<\/strong>\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0cMongoDB \u6e38\u6a19\u7684\u8d85\u6642\u6642\u9593\u70ba\u5341\u5206\u9418\u3002\u5982\u679c\u5ba2\u6236\u7aef\u5728\u6b64\u671f\u9650\u5167\u672a\u5f9e\u6e38\u6a19\u4e2d\u6aa2\u7d22\u6587\u6a94\uff0c\u5247\u6e38\u6a19\u5c07\u88ab\u95dc\u9589\uff0c\u96a8\u5f8c\u5c0d\u5176\u7684\u8a2a\u554f\u5c07\u5c0e\u81f4 CursorNotFound \u932f\u8aa4\u3002<\/li>\n<li><strong>\u660e\u78ba\u7684\u6e38\u6a19\u95dc\u9589\uff1a<\/strong>\u5982\u679c\u4f3a\u670d\u5668\u8a8d\u70ba\u8a72\u6e38\u6a19\u4e0d\u518d\u9700\u8981\uff0c\u6216\u8005\u5df2\u9054\u5230\u5176\u5167\u5b58\u9650\u5236\uff0c\u5247\u53ef\u4ee5\u660e\u78ba\u95dc\u9589\u6e38\u6a19\u3002<\/li>\n<li><strong>\u5206\u7247\u9077\u79fb\uff1a<\/strong>\u5982\u679c\u60a8\u4f7f\u7528\u5206\u7247\u96c6\u7fa4\uff0c\u5247\u5728\u5206\u7247\u9077\u79fb\u671f\u9593\uff0c\u6e38\u6a19\u5f9e\u4e00\u500b\u5206\u7247\u79fb\u52d5\u5230\u53e6\u4e00\u500b\u5206\u7247\u6642\uff0c\u53ef\u80fd\u6703\u767c\u751f\u6b64\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-mongodb-error-code-43-cursornotfound-OkkZBhyVFE\">\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound<\/h2>\n<p>\u70ba\u4e86\u89e3\u6c7a CursorNotFound \u932f\u8aa4\uff0c\u60a8\u53ef\u4ee5\u63a1\u53d6\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-reissue-the-query-OkkZBhyVFE\">1. \u91cd\u65b0\u767c\u9001\u67e5\u8a62<\/h3>\n<p>\u5982\u679c\u932f\u8aa4\u662f\u7531\u65bc\u6e38\u6a19\u8d85\u6642\u5f15\u8d77\u7684\uff0c\u60a8\u53ef\u4ee5\u7c21\u55ae\u5730\u91cd\u65b0\u767c\u9001\u67e5\u8a62\u4ee5\u7372\u5f97\u4e00\u500b\u65b0\u7684\u6e38\u6a19\u3002\u8acb\u78ba\u4fdd\u5728\u8d85\u6642\u671f\u9593\u5167\u5f9e\u6e38\u6a19\u4e2d\u6aa2\u7d22\u6587\u6a94\uff0c\u4ee5\u907f\u514d\u518d\u6b21\u9047\u5230\u932f\u8aa4\u3002<\/p>\n<h3 id=\"2-increase-the-cursor-timeout-OkkZBhyVFE\">2. \u589e\u52a0\u6e38\u6a19\u8d85\u6642\u6642\u9593<\/h3>\n<p>\u5982\u679c\u60a8\u7d93\u5e38\u9047\u5230 CursorNotFound \u932f\u8aa4\uff0c\u53ef\u4ee5\u5c07\u6e38\u6a19\u7684\u8d85\u6642\u503c\u589e\u52a0\u5230\u66f4\u9ad8\u7684\u6578\u503c\u3002\u9019\u53ef\u4ee5\u901a\u904e\u5728\u57f7\u884c\u67e5\u8a62\u6642\u8a2d\u7f6e &#8220;maxTimeMS&#8221; \u9078\u9805\u4f86\u5be6\u73fe\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>db.collection.find(query).maxTimeMS(600000) \/\/ \u5c07\u8d85\u6642\u8a2d\u7f6e\u70ba 10 \u5206\u9418<\/code><\/pre>\n<h3 id=\"3-check-for-explicit-cursor-closure-OkkZBhyVFE\">3. \u6aa2\u67e5\u660e\u78ba\u7684\u6e38\u6a19\u95dc\u9589<\/h3>\n<p>\u5982\u679c\u4f3a\u670d\u5668\u660e\u78ba\u95dc\u9589\u4e86\u6e38\u6a19\uff0c\u60a8\u53ef\u4ee5\u4fee\u6539\u4ee3\u78bc\u4ee5\u512a\u96c5\u5730\u8655\u7406\u6b64\u60c5\u6cc1\u3002\u6aa2\u67e5\u662f\u5426\u6709\u4efb\u4f55\u6703\u89f8\u767c\u95dc\u9589\u7684\u689d\u4ef6\uff0c\u4e26\u6839\u64da\u9700\u8981\u8abf\u6574\u4ee3\u78bc\u3002<\/p>\n<h3 id=\"4-monitor-shard-migration-OkkZBhyVFE\">4. \u76e3\u63a7\u5206\u7247\u9077\u79fb<\/h3>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u5206\u7247\u96c6\u7fa4\uff0c\u4e26\u4e14\u5728\u5206\u7247\u9077\u79fb\u6642\u767c\u751f\u932f\u8aa4\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u67e5\u770b MongoDB \u65e5\u8a8c\u4f86\u76e3\u63a7\u9077\u79fb\u904e\u7a0b\u3002\u5728\u8a2a\u554f\u6e38\u6a19\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u9077\u79fb\u5df2\u6210\u529f\u5b8c\u6210\u3002<\/p>\n<h2 id=\"summary-OkkZBhyVFE\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u4e4b\uff0cMongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 43 &#8211; CursorNotFound \u53ef\u80fd\u5728\u6e38\u6a19\u4e0d\u518d\u53ef\u7528\u65bc\u4f3a\u670d\u5668\u6642\u767c\u751f\u3002\u9019\u53ef\u80fd\u662f\u7531\u6e38\u6a19\u8d85\u6642\u3001\u660e\u78ba\u95dc\u9589\u6216\u5206\u7247\u9077\u79fb\u6240\u81f4\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u53ef\u4ee5\u91cd\u65b0\u767c\u9001\u67e5\u8a62\u3001\u589e\u52a0\u6e38\u6a19\u8d85\u6642\u3001\u8655\u7406\u660e\u78ba\u95dc\u9589\u7684\u60c5\u6cc1\u6216\u76e3\u63a7\u5206\u7247\u9077\u79fb\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 VPS \u4e3b\u6a5f\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u8a2a\u554f <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u6211\u5011\u7684\u9ad8\u6548\u80fd VPS \u4e3b\u6a5f\u670d\u52d9\u80fd\u70ba\u60a8\u7684 MongoDB \u90e8\u7f72\u63d0\u4f9b\u6240\u9700\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u64f4\u5c55\u6027\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":[4925],"tags":[],"class_list":["post-21638","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21638","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=21638"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21638\/revisions"}],"predecessor-version":[{"id":23785,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21638\/revisions\/23785"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}