{"id":70974,"date":"2024-02-02T10:41:12","date_gmt":"2024-02-02T02:41:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=70974"},"modified":"2024-02-02T10:41:13","modified_gmt":"2024-02-02T02:41:13","slug":"%e5%9c%a8mongodb%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bc%98%e5%8c%96%e6%9f%a5%e8%af%a2%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/70974.html","title":{"rendered":"\u5728MongoDB\u4e2d\u5982\u4f55\u4f18\u5316\u67e5\u8be2\u6027\u80fd"},"content":{"rendered":"<p>\u6458\u8981\uff1a\u5728<strong>MongoDB<\/strong>\u4e2d\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u7684\u5173\u952e\u70b9\u5305\u62ec<strong>1\u3001\u6b63\u786e\u521b\u5efa\u548c\u4f7f\u7528\u7d22\u5f15<\/strong>\u30012\u3001\u4f18\u5316\u67e5\u8be2\u8bed\u53e5\u548c\u6295\u5f71\u30013\u3001\u5229\u7528\u7f13\u5b58\u673a\u5236\u30014\u3001\u5408\u7406\u5206\u7247\u548c\u590d\u5236\u96c6\u30015\u3001\u76d1\u63a7\u6027\u80fd\u5e76\u5206\u6790\u6162\u67e5\u8be2\u3002\u7d22\u5f15\u5bf9\u4e8e\u67e5\u8be2\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff0c<strong>\u6b63\u786e\u521b\u5efa\u548c\u4f7f\u7528\u7d22\u5f15<\/strong>\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u907f\u514d\u5168\u8868\u626b\u63cf\uff0c\u51cf\u5c11\u78c1\u76d8I\/O\u6d88\u8017\u3002\u5bf9\u4e8e\u67e5\u8be2\u6027\u80fd\u4f18\u5316\uff0c\u4e86\u89e3\u548c\u5e94\u7528\u6b63\u786e\u7684\u7d22\u5f15\u662f\u57fa\u7840\u4e14\u4e0d\u5bb9\u5ffd\u89c6\u7684\u6b65\u9aa4\u3002<\/p>\n<p>\u5173\u4e8e<strong>1\u3001\u6b63\u786e\u521b\u5efa\u548c\u4f7f\u7528\u7d22\u5f15<\/strong>\uff0c\u9700\u8981\u4f9d\u636e\u67e5\u8be2\u6a21\u5f0f\u9009\u62e9\u5408\u9002\u7c7b\u578b\u7684\u7d22\u5f15\uff0c\u5e76\u4fdd\u8bc1\u7d22\u5f15\u7684\u9009\u62e9\u6027\u9ad8\uff1b\u5b9a\u671f\u7ef4\u62a4\u7d22\u5f15\uff0c\u4ee5\u4fdd\u6301\u67e5\u8be2\u7684\u9ad8\u6548\u6027\u3002<\/p>\n<h2><strong>\u4e00\u3001\u521b\u5efa\u548c\u4f7f\u7528\u7d22\u5f15\u7684\u7b56\u7565<\/strong><\/h2>\n<p>\u4e3a\u786e\u4fdd\u67e5\u8be2\u901f\u5ea6\uff0c\u9002\u5f53\u7684\u7d22\u5f15\u8bbe\u8ba1\u4e0d\u53ef\u6216\u7f3a\u3002<strong>\u521b\u5efa\u590d\u5408\u7d22\u5f15\u4ee5\u5339\u914d\u67e5\u8be2\u6a21\u5f0f<\/strong>\u3001\u8003\u8651\u6392\u5e8f\u548c<strong>\u8303\u56f4\u67e5\u8be2<\/strong>\u65f6\u7d22\u5f15\u7684\u987a\u5e8f\u3001\u907f\u514d\u5197\u4f59\u548c\u8fc7\u591a\u4e0d\u5fc5\u8981\u7684\u7d22\u5f15\uff0c\u8fd9\u4e9b\u662f\u4f18\u5316\u7684\u5173\u952e\u6240\u5728\u3002\u540c\u65f6\uff0c\u4f7f\u7528\u7d22\u5f15\u524d\uff0c\u5e94\u5229\u7528<strong>expl<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n()\u65b9\u6cd5\u7406\u89e3\u67e5\u8be2\u8ba1\u5212\u548c\u7d22\u5f15\u5229\u7528\u60c5\u51b5<\/strong>\u3002<\/p>\n<h2><strong>\u4e8c\u3001\u67e5\u8be2\u8bed\u53e5\u53ca\u6295\u5f71\u4f18\u5316<\/strong><\/h2>\n<p>\u7f16\u5199\u9ad8\u6548\u7684\u67e5\u8be2\u8bed\u53e5\uff0c\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u6570\u636e\u5904\u7406\u3002\u4e00\u4e2a\u5178\u578b\u7684\u4f8b\u5b50\u662f<strong>\u4ec5\u83b7\u53d6\u5fc5\u8981\u7684\u5b57\u6bb5<\/strong>\uff0c\u800c\u975e\u6574\u4e2a\u6587\u6863\uff1b\u51cf\u8f7b\u7f51\u7edc\u548c\u5185\u5b58\u8d1f\u62c5\u3002\u5229\u7528find()\u7684\u6295\u5f71\u53c2\u6570\uff0c\u6765\u9650\u5236\u8fd4\u56de\u7684\u5b57\u6bb5\u53ef\u4ee5\u5927\u5e45\u63d0\u5347\u6027\u80fd\u3002<\/p>\n<h2><strong>\u4e09\u3001\u7f13\u5b58\u673a\u5236\u8fd0\u7528<\/strong><\/h2>\n<p>MongoDB\u7684<strong>\u5de5\u4f5c\u96c6\uff08Working Set\uff09<\/strong>\u548c<strong>\u7d22\u5f15\u7f13\u5b58<\/strong>\u5bf9\u6027\u80fd\u81f3\u5173\u91cd\u8981\u3002\u786e\u4fdd\u5e38\u7528\u7684\u6570\u636e\u4fdd\u6301\u5728RAM\u4e2d\uff0c\u53ef\u4ee5\u6781\u5927\u52a0\u5feb\u67e5\u8be2\u901f\u5ea6\u3002\u8fd0\u7528\u597dMongoDB\u7684\u7f13\u5b58\u673a\u5236\uff0c\u5408\u7406\u5206\u914d\u5185\u5b58\u8d44\u6e90\u3002<\/p>\n<h2><strong>\u56db\u3001\u5206\u7247\u548c\u590d\u5236\u96c6\u7684\u7b56\u7565<\/strong><\/h2>\n<p>\u5728\u9762\u5bf9\u5e9e\u5927\u6570\u636e\u96c6\u65f6\uff0c\u6570\u636e\u5e93\u6c34\u5e73\u6269\u5c55\u662f\u89e3\u51b3\u74f6\u9888\u7684\u529e\u6cd5\u4e4b\u4e00\u3002\u5e94\u7528<strong>\u5206\u7247\u6765\u5206\u6563\u8bfb\u5199\u538b\u529b<\/strong>\u548c\u5229\u7528\u590d\u5236\u96c6\u4fdd\u8bc1\u6570\u636e\u9ad8\u53ef\u7528\u6027\uff0c\u662f\u4f18\u5316\u6027\u80fd\u548c\u63d0\u4f9b\u6269\u5c55\u80fd\u529b\u7684\u5173\u952e\u65b9\u6cd5\u3002<\/p>\n<h2><strong>\u4e94\u3001\u6027\u80fd\u76d1\u63a7\u4e0e\u6162\u67e5\u8be2\u5206\u6790<\/strong><\/h2>\n<p><strong>\u6301\u7eed\u76d1\u63a7\u6027\u80fd<\/strong>\u53ef\u4ee5\u53d1\u73b0\u6f5c\u5728\u95ee\u9898\uff0c\u5229\u7528MongoDB\u7684\u6162\u67e5\u8be2\u65e5\u5fd7\u8fdb\u884c\u6162\u67e5\u8be2\u5206\u6790\uff0c\u53ca\u65f6\u4f18\u5316\u4e0d\u8db3\u4e4b\u5904\u3002\u8fd9\u662f\u786e\u4fdd\u6570\u636e\u5e93\u6301\u7eed\u8fd0\u884c\u5728\u6700\u4f73\u72b6\u6001\u4e0b\u7684\u6709\u6548\u624b\u6bb5\u3002<\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\u7684\u5408\u7406\u8fd0\u7528\uff0c\u53ef\u4ee5\u5728MongoDB\u4e2d\u663e\u8457\u63d0\u5347\u67e5\u8be2\u6027\u80fd\uff0c\u5e76\u4fdd\u6301\u6570\u636e\u5e93\u7684\u9ad8\u6548\u548c\u7a33\u5b9a\u3002<\/p>\n<p> <strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><strong>\u5982\u4f55\u5728MongoDB\u4e2d\u901a\u8fc7\u7d22\u5f15\u6765\u4f18\u5316\u67e5\u8be2\u6027\u80fd\uff1f<\/strong><\/p>\n<p>\u4f7f\u7528\u7d22\u5f15\u662f\u4f18\u5316MongoDB\u67e5\u8be2\u6027\u80fd\u7684\u4e00\u79cd\u5e38\u7528\u65b9\u6cd5\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u5b57\u6bb5\u4e0a\u521b\u5efa\u7d22\u5f15\u6765\u5e2e\u52a9\u6570\u636e\u5e93\u7cfb\u7edf\u66f4\u5feb\u5730\u5b9a\u4f4d\u548c\u8bbf\u95ee\u6570\u636e\u3002\u5728MongoDB\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528`createIndex()`\u65b9\u6cd5\u6765\u521b\u5efa\u7d22\u5f15\uff0c\u7136\u540e\u5728\u67e5\u8be2\u65f6\u4f7f\u7528`explain()`\u65b9\u6cd5\u6765\u67e5\u770b\u67e5\u8be2\u6267\u884c\u8ba1\u5212\uff0c\u786e\u4fdd\u67e5\u8be2\u4f18\u5316\u5668\u6b63\u5728\u4f7f\u7528\u7d22\u5f15\u3002<\/p>\n<p><strong>\u9664\u4e86\u4f7f\u7528\u7d22\u5f15\uff0c\u8fd8\u6709\u54ea\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u4f18\u5316MongoDB\u7684\u67e5\u8be2\u6027\u80fd\uff1f<\/strong><\/p>\n<p>\u9664\u4e86\u4f7f\u7528\u7d22\u5f15\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u5408\u7406\u8bbe\u8ba1\u6570\u636e\u6a21\u578b\u3001\u4f7f\u7528\u6295\u5f71\u64cd\u4f5c\u7b26\u51cf\u5c11\u8fd4\u56de\u7684\u5b57\u6bb5\u3001\u5229\u7528\u805a\u5408\u7ba1\u9053\u6846\u67b6\u8fdb\u884c\u590d\u6742\u6570\u636e\u5904\u7406\u3001\u5bf9\u67e5\u8be2\u8fdb\u884c\u5206\u7247\u4ee5\u53ca\u4f7f\u7528\u9002\u5f53\u7684\u786c\u4ef6\u8d44\u6e90\u6765\u8fdb\u4e00\u6b65\u4f18\u5316MongoDB\u7684\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528MongoDB\u7684\u5206\u7247\u6765\u4f18\u5316\u67e5\u8be2\u6027\u80fd\uff1f<\/strong><\/p>\n<p>MongoDB\u7684\u5206\u7247\u529f\u80fd\u53ef\u4ee5\u6c34\u5e73\u6269\u5c55\u6570\u636e\uff0c\u5e2e\u52a9\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u8bfb\u5199\u8bf7\u6c42\uff0c\u4ece\u800c\u63d0\u5347\u67e5\u8be2\u6027\u80fd\u3002\u4f7f\u7528\u5206\u7247\u53ef\u4ee5\u5c06\u6570\u636e\u5206\u5e03\u5230\u591a\u4e2a\u96c6\u7fa4\u8282\u70b9\u4e0a\uff0c\u6709\u6548\u5206\u62c5\u6570\u636e\u8bbf\u95ee\u538b\u529b\u3002\u5728MongoDB\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528`sh.shardCollection()`\u65b9\u6cd5\u6765\u5c06\u96c6\u5408\u5206\u7247\uff0c\u7136\u540e\u901a\u8fc7\u5408\u7406\u914d\u7f6e\u5206\u7247\u952e\u6765\u8fbe\u5230\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u7684\u76ee\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u6458\u8981\uff1a\u5728MongoDB\u4e2d\u4f18\u5316\u67e5\u8be2\u6027\u80fd\u7684\u5173\u952e\u70b9\u5305\u62ec1\u3001\u6b63\u786e\u521b\u5efa\u548c\u4f7f\u7528\u7d22\u5f15\u30012\u3001\u4f18\u5316\u67e5\u8be2\u8bed\u53e5\u548c\u6295\u5f71\u30013\u3001\u5229\u7528\u7f13\u5b58\u673a [&hellip;]","protected":false},"author":1,"featured_media":70976,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/70974"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=70974"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/70974\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/70976"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=70974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=70974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=70974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}