{"id":21778,"date":"2024-01-02T15:09:28","date_gmt":"2024-01-02T15:09:28","guid":{"rendered":"https:\/\/server.hk\/blog\/21778\/"},"modified":"2024-11-14T10:27:11","modified_gmt":"2024-11-14T02:27:11","slug":"how-to-fix-mongodb-error-code-193-noshardingenabled","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21778\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 193 &#8211; NoShardingEnabled"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-193-noshardingenabled-IqAsIuQVoq\">\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 193 &#8211; NoShardingEnabled<\/h1>\n<p>MongoDB \u662f\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90 NoSQL \u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u9ad8\u6027\u80fd\u3001\u53ef\u64f4\u5c55\u6027\u548c\u9748\u6d3b\u6027\u3002\u5b83\u5141\u8a31\u60a8\u5feb\u901f\u6709\u6548\u5730\u5b58\u5132\u548c\u6aa2\u7d22\u5927\u91cf\u6578\u64da\u3002\u7136\u800c\uff0c\u50cf\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0cMongoDB \u4e5f\u53ef\u80fd\u9047\u5230\u6703\u5e72\u64fe\u6b63\u5e38\u904b\u884c\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 193 &#8211; NoShardingEnabled\u3002<\/p>\n<h2 id=\"understanding-mongodb-sharding-IqAsIuQVoq\">\u7406\u89e3 MongoDB \u5206\u7247<\/h2>\n<p>\u5728\u6211\u5011\u6df1\u5165\u4fee\u5fa9 NoShardingEnabled \u932f\u8aa4\u4e4b\u524d\uff0c\u8b93\u6211\u5011\u9996\u5148\u4e86\u89e3\u4ec0\u9ebc\u662f MongoDB \u5206\u7247\u3002\u5206\u7247\u662f\u5c07\u6578\u64da\u5206\u4f48\u5230\u591a\u53f0\u6a5f\u5668\u6216\u670d\u52d9\u5668\u4e0a\u7684\u904e\u7a0b\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u4e26\u8655\u7406\u5927\u578b\u6578\u64da\u96c6\u3002\u5b83\u901a\u904e\u5c07\u6578\u64da\u5283\u5206\u70ba\u7a31\u70ba\u5206\u7247\u7684\u5c0f\u584a\uff0c\u5141\u8a31\u60a8\u6c34\u5e73\u64f4\u5c55 MongoDB \u90e8\u7f72\u3002<\/p>\n<p>\u6bcf\u500b\u5206\u7247\u5305\u542b\u60a8\u7684\u6578\u64da\u5b50\u96c6\uff0cMongoDB \u6839\u64da\u5206\u7247\u9375\u81ea\u52d5\u5c07\u6578\u64da\u5206\u4f48\u5230\u591a\u500b\u5206\u7247\u3002\u9019\u7a2e\u5206\u4f48\u78ba\u4fdd\u6578\u64da\u5747\u52fb\u5206\u4f48\uff0c\u4e26\u5141\u8a31\u67e5\u8a62\u7684\u4e26\u884c\u8655\u7406\uff0c\u5f9e\u800c\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<h2 id=\"the-noshardingenabled-error-IqAsIuQVoq\">NoShardingEnabled \u932f\u8aa4<\/h2>\n<p>NoShardingEnabled \u932f\u8aa4\u767c\u751f\u5728\u60a8\u5617\u8a66\u5728\u672a\u555f\u7528\u5206\u7247\u7684 MongoDB \u90e8\u7f72\u4e0a\u57f7\u884c\u9700\u8981\u5206\u7247\u7684\u64cd\u4f5c\u6642\u3002\u5fc5\u9808\u5728\u60a8\u7684 MongoDB \u90e8\u7f72\u4e0a\u660e\u78ba\u555f\u7528\u5206\u7247\uff0c\u4ee5\u5229\u7528\u5176\u512a\u52e2\u3002<\/p>\n<p>\u7576\u60a8\u9047\u5230 NoShardingEnabled \u932f\u8aa4\u6642\uff0c\u60a8\u53ef\u80fd\u6703\u770b\u5230\u985e\u4f3c\u4ee5\u4e0b\u7684\u932f\u8aa4\u6d88\u606f\uff1a<\/p>\n<pre>\r\n{\r\n  \"ok\" : 0,\r\n  \"errmsg\" : \"NoShardingEnabled: \u7121\u6cd5\u57f7\u884c\u64cd\u4f5c\u3002\u547d\u540d\u7a7a\u9593\u672a\u555f\u7528\u5206\u7247\",\r\n  \"code\" : 193,\r\n  \"codeName\" : \"NoShardingEnabled\"\r\n}\r\n<\/pre>\n<h2 id=\"fixing-the-noshardingenabled-error-IqAsIuQVoq\">\u4fee\u5fa9 NoShardingEnabled \u932f\u8aa4<\/h2>\n<p>\u8981\u4fee\u5fa9 NoShardingEnabled \u932f\u8aa4\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684 MongoDB \u90e8\u7f72\u4e0a\u555f\u7528\u5206\u7247\u3002\u4ee5\u4e0b\u662f\u9700\u8981\u9075\u5faa\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"step-1-connect-to-mongodb-IqAsIuQVoq\">\u6b65\u9a5f 1\uff1a\u9023\u63a5\u5230 MongoDB<\/h3>\n<p>\u6253\u958b\u7d42\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u4f7f\u7528 MongoDB shell \u6216 MongoDB \u5ba2\u6236\u7aef\u9023\u63a5\u5230\u60a8\u7684 MongoDB \u90e8\u7f72\u3002\u60a8\u9700\u8981\u7ba1\u7406\u6b0a\u9650\u624d\u80fd\u555f\u7528\u5206\u7247\u3002<\/p>\n<pre>\r\nmongo --host  --port  --username  --password  --authenticationDatabase admin\r\n<\/pre>\n<h3 id=\"step-2-enable-sharding-IqAsIuQVoq\">\u6b65\u9a5f 2\uff1a\u555f\u7528\u5206\u7247<\/h3>\n<p>\u9023\u63a5\u5f8c\uff0c\u901a\u904e\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u555f\u7528\u5206\u7247\uff1a<\/p>\n<pre>\r\nsh.enableSharding(\"\")\r\n<\/pre>\n<p>\u5c07  \u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u555f\u7528\u5206\u7247\u7684\u6578\u64da\u5eab\u540d\u7a31\u3002\u6b64\u547d\u4ee4\u70ba\u6307\u5b9a\u7684\u6578\u64da\u5eab\u555f\u7528\u5206\u7247\u3002<\/p>\n<h3 id=\"step-3-shard-a-collection-IqAsIuQVoq\">\u6b65\u9a5f 3\uff1a\u5c0d\u96c6\u5408\u9032\u884c\u5206\u7247<\/h3>\n<p>\u5728\u70ba\u6578\u64da\u5eab\u555f\u7528\u5206\u7247\u5f8c\uff0c\u60a8\u9700\u8981\u5c0d\u8a72\u6578\u64da\u5eab\u4e2d\u7684\u96c6\u5408\u9032\u884c\u5206\u7247\u3002\u8981\u5c0d\u96c6\u5408\u9032\u884c\u5206\u7247\uff0c\u8acb\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>\r\nsh.shardCollection(\".\", { \"\": \"hashed\" })\r\n<\/pre>\n<p>\u5c07  \u66ff\u63db\u70ba\u5305\u542b\u60a8\u8981\u5206\u7247\u7684\u96c6\u5408\u7684\u6578\u64da\u5eab\u540d\u7a31\uff0c  \u66ff\u63db\u70ba\u96c6\u5408\u540d\u7a31\uff0c\u4e26\u5c07  \u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u7528\u4f5c\u5206\u7247\u9375\u7684\u5b57\u6bb5\u3002 &#8220;hashed&#8221; \u503c\u6307\u5b9a MongoDB \u61c9\u4f7f\u7528\u54c8\u5e0c\u5206\u7247\u9375\u3002<\/p>\n<h3 id=\"step-4-verify-sharding-IqAsIuQVoq\">\u6b65\u9a5f 4\uff1a\u9a57\u8b49\u5206\u7247<\/h3>\n<p>\u6700\u5f8c\uff0c\u901a\u904e\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u9a57\u8b49\u5206\u7247\u662f\u5426\u5df2\u555f\u7528\u4e26\u6b63\u5e38\u5de5\u4f5c\uff1a<\/p>\n<pre>\r\nsh.status()\r\n<\/pre>\n<p>\u6b64\u547d\u4ee4\u986f\u793a\u6709\u95dc\u5206\u7247\u96c6\u7fa4\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u555f\u7528\u7684\u5206\u7247\u548c\u5206\u7247\u7684\u96c6\u5408\u3002<\/p>\n<h2 id=\"summary-IqAsIuQVoq\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u8a0e\u8ad6\u4e86 MongoDB \u4e2d\u7684 NoShardingEnabled \u932f\u8aa4\u53ca\u5176\u4fee\u5fa9\u65b9\u6cd5\u3002\u5206\u7247\u662f MongoDB \u7684\u4e00\u500b\u5f37\u5927\u529f\u80fd\uff0c\u5141\u8a31\u60a8\u5c07\u6578\u64da\u5206\u4f48\u5230\u591a\u53f0\u6a5f\u5668\u4e0a\uff0c\u4ee5\u63d0\u9ad8\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u3002\u901a\u904e\u9075\u5faa\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u5728\u60a8\u7684 MongoDB \u90e8\u7f72\u4e0a\u555f\u7528\u5206\u7247\u4e26\u89e3\u6c7a NoShardingEnabled \u932f\u8aa4\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 VPS \u4e3b\u6a5f\u63d0\u4f9b\u5546\u4f86\u6258\u7ba1\u60a8\u7684 MongoDB \u90e8\u7f72\uff0c\u53ef\u4ee5\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u901a\u904e\u4ed6\u5011\u7684\u9802\u5c16 VPS \u89e3\u6c7a\u65b9\u6848\uff0c\u60a8\u53ef\u4ee5\u78ba\u4fdd\u60a8\u7684 MongoDB \u61c9\u7528\u7a0b\u5e8f\u5177\u6709\u9ad8\u6027\u80fd\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":[101],"tags":[],"class_list":["post-21778","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21778","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=21778"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21778\/revisions"}],"predecessor-version":[{"id":23595,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21778\/revisions\/23595"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}