{"id":21834,"date":"2024-01-02T16:05:23","date_gmt":"2024-01-02T16:05:23","guid":{"rendered":"https:\/\/server.hk\/blog\/21834\/"},"modified":"2024-11-14T10:26:20","modified_gmt":"2024-11-14T02:26:20","slug":"how-to-fix-mongodb-error-code-252-reentrancynotallowed","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21834\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-252-reentrancynotallowed-EtMGRtiuKG\">\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed<\/h1>\n<p>MongoDB \u662f\u4e00\u7a2e\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\u4e0d\u904e\uff0c\u50cf\u4efb\u4f55\u8edf\u9ad4\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u9700\u8981\u89e3\u6c7a\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u5c31\u662f MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u542b\u7fa9\u4ee5\u53ca\u5982\u4f55\u4fee\u5fa9\u3002<\/p>\n<h2 id=\"understanding-mongodb-error-code-252-reentrancynotallowed-EtMGRtiuKG\">\u7406\u89e3 MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed<\/h2>\n<p>\u7576\u4f60\u9047\u5230 MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed \u6642\uff0c\u610f\u5473\u8457\u4f60\u5617\u8a66\u5c0d MongoDB \u9023\u63a5\u9032\u884c\u91cd\u5165\u64cd\u4f5c\u3002\u91cd\u5165\u6307\u7684\u662f\u51fd\u6578\u88ab\u4e2d\u65b7\u5f8c\uff0c\u5728\u5176\u5148\u524d\u7684\u57f7\u884c\u5b8c\u6210\u4e4b\u524d\u518d\u6b21\u88ab\u8abf\u7528\u7684\u80fd\u529b\u3002MongoDB \u4e0d\u5141\u8a31\u91cd\u5165\u64cd\u4f5c\uff0c\u56e0\u70ba\u5b83\u5011\u53ef\u80fd\u5c0e\u81f4\u610f\u5916\u884c\u70ba\u548c\u6578\u64da\u640d\u58de\u3002<\/p>\n<p>\u9019\u500b\u932f\u8aa4\u901a\u5e38\u767c\u751f\u5728\u4f60\u6709\u5d4c\u5957\u64cd\u4f5c\u6216\u56de\u547c\uff0c\u8a66\u5716\u5728\u540c\u4e00\u9023\u63a5\u4e0a\u57f7\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u6642\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u500b\u9032\u884c\u6578\u64da\u5eab\u67e5\u8a62\u7684\u51fd\u6578\uff0c\u5728\u8a72\u51fd\u6578\u4e2d\uff0c\u4f60\u8abf\u7528\u4e86\u53e6\u4e00\u500b\u4e5f\u5728\u540c\u4e00\u9023\u63a5\u4e0a\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u51fd\u6578\uff0c\u4f60\u53ef\u80fd\u6703\u9047\u5230\u9019\u500b\u932f\u8aa4\u3002<\/p>\n<h2 id=\"fixing-mongodb-error-code-252-reentrancynotallowed-EtMGRtiuKG\">\u4fee\u5fa9 MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed<\/h2>\n<p>\u8981\u4fee\u5fa9 MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed\uff0c\u4f60\u9700\u8981\u78ba\u4fdd\u4f60\u6c92\u6709\u5728\u540c\u4e00 MongoDB \u9023\u63a5\u4e0a\u9032\u884c\u91cd\u5165\u64cd\u4f5c\u3002\u9019\u88e1\u6709\u4e00\u4e9b\u6b65\u9a5f\u53ef\u4ee5\u5e6b\u52a9\u4f60\u89e3\u6c7a\u9019\u500b\u932f\u8aa4\uff1a<\/p>\n<h3 id=\"1-check-for-nested-operations-EtMGRtiuKG\">1. \u6aa2\u67e5\u5d4c\u5957\u64cd\u4f5c<\/h3>\n<p>\u67e5\u770b\u60a8\u7684\u4ee3\u78bc\u4e26\u8b58\u5225\u53ef\u80fd\u5c0e\u81f4\u554f\u984c\u7684\u4efb\u4f55\u5d4c\u5957\u64cd\u4f5c\u6216\u56de\u547c\u3002\u5c0b\u627e\u57f7\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u51fd\u6578\u6216\u65b9\u6cd5\uff0c\u78ba\u4fdd\u5b83\u5011\u6c92\u6709\u5728\u5176\u4ed6\u4e5f\u5728\u540c\u4e00\u9023\u63a5\u4e0a\u57f7\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u51fd\u6578\u5167\u90e8\u88ab\u8abf\u7528\u3002<\/p>\n<h3 id=\"2-use-separate-connections-EtMGRtiuKG\">2. \u4f7f\u7528\u7368\u7acb\u9023\u63a5<\/h3>\n<p>\u5982\u679c\u4f60\u9700\u8981\u540c\u6642\u9032\u884c\u591a\u500b\u6578\u64da\u5eab\u64cd\u4f5c\uff0c\u8003\u616e\u70ba\u6bcf\u4e00\u500b\u64cd\u4f5c\u4f7f\u7528\u7368\u7acb\u7684\u9023\u63a5\u3002\u9019\u78ba\u4fdd\u6bcf\u500b\u64cd\u4f5c\u90fd\u6709\u81ea\u5df1\u7684\u9023\u63a5\uff0c\u907f\u514d\u4e86\u7531\u91cd\u5165\u64cd\u4f5c\u5f15\u8d77\u7684\u885d\u7a81\u3002<\/p>\n<h3 id=\"3-use-async-await-or-promises-EtMGRtiuKG\">3. \u4f7f\u7528 Async\/Await \u6216 Promises<\/h3>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528\u56de\u547c\u9032\u884c\u975e\u540c\u6b65\u64cd\u4f5c\uff0c\u8003\u616e\u4f7f\u7528 async\/await \u6216 promises \u66ff\u4ee3\u3002\u9019\u4e9b\u73fe\u4ee3 JavaScript \u7279\u6027\u63d0\u4f9b\u4e86\u66f4\u597d\u7684\u63a7\u5236\u975e\u540c\u6b65\u64cd\u4f5c\u4e26\u53ef\u4ee5\u5e6b\u52a9\u907f\u514d\u91cd\u5165\u64cd\u4f5c\u3002<\/p>\n<h3 id=\"4-refactor-your-code-EtMGRtiuKG\">4. \u91cd\u69cb\u60a8\u7684\u4ee3\u78bc<\/h3>\n<p>\u5982\u679c\u4f60\u767c\u73fe\u7121\u6cd5\u8f15\u6613\u5206\u96e2\u6216\u89e3\u6c7a\u7684\u5d4c\u5957\u64cd\u4f5c\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u91cd\u69cb\u4f60\u7684\u4ee3\u78bc\u3002\u8003\u616e\u5c07\u5d4c\u5957\u64cd\u4f5c\u62c6\u5206\u70ba\u55ae\u7368\u7684\u51fd\u6578\uff0c\u6216\u91cd\u65b0\u7d44\u7e54\u60a8\u7684\u4ee3\u78bc\u4ee5\u907f\u514d\u91cd\u5165\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"summary-EtMGRtiuKG\">\u6458\u8981<\/h2>\n<p>MongoDB \u932f\u8aa4\u78bc &#8211; 252 &#8211; ReentrancyNotAllowed \u767c\u751f\u5728\u4f60\u5617\u8a66\u5728\u540c\u4e00 MongoDB \u9023\u63a5\u4e0a\u9032\u884c\u91cd\u5165\u64cd\u4f5c\u6642\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u4f60\u9700\u8981\u78ba\u4fdd\u4f60\u672a\u9032\u884c\u76f8\u4e92\u885d\u7a81\u7684\u5d4c\u5957\u64cd\u4f5c\u6216\u56de\u547c\u3002\u4f7f\u7528\u7368\u7acb\u9023\u63a5\uff0c\u8003\u616e\u4f7f\u7528 async\/await \u6216 promises\uff0c\u4e26\u5728\u5fc5\u8981\u6642\u91cd\u69cb\u4f60\u7684\u4ee3\u78bc\u3002<\/p>\n<p>\u82e5\u5c0b\u627e\u53ef\u9760\u4e14\u9ad8\u6027\u80fd\u7684 VPS \u4e3b\u6a5f\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u6211\u5011\u7684\u9999\u6e2f VPS \u4e3b\u6a5f\u670d\u52d9\u63d0\u4f9b\u9802\u7d1a\u6027\u80fd\u53ca\u64f4\u5c55\u6027\u4ee5\u6eff\u8db3\u60a8\u7684\u5546\u696d\u9700\u6c42\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-21834","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21834","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=21834"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21834\/revisions"}],"predecessor-version":[{"id":23523,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21834\/revisions\/23523"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}