{"id":247368,"date":"2024-01-02T21:10:20","date_gmt":"2024-01-02T13:10:20","guid":{"rendered":"https:\/\/www.idc.net\/help\/247368\/"},"modified":"2024-01-02T21:10:20","modified_gmt":"2024-01-02T13:10:20","slug":"mongodb-%e6%9c%af%e8%af%ad-%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/247368\/","title":{"rendered":"MongoDB \u672f\u8bed &#8211; \u6587\u672c\u7d22\u5f15"},"content":{"rendered":"<p><title id=\"mongodb-%e6%9c%af%e8%af%ad-%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95-ioHqnSclJi\">MongoDB \u672f\u8bed - \u6587\u672c\u7d22\u5f15<\/title><\/p>\n<h1 id=\"mongodb-%e6%9c%af%e8%af%ad-%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95-ioHqnSclJi\">MongoDB \u672f\u8bed - \u6587\u672c\u7d22\u5f15<\/h1>\n<h2 id=\"%e4%bb%80%e4%b9%88%e6%98%af%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95%ef%bc%9f-ioHqnSclJi\">\u4ec0\u4e48\u662f\u6587\u672c\u7d22\u5f15\uff1f<\/h2>\n<p>\u6587\u672c\u7d22\u5f15\u662fMongoDB\u4e2d\u4e00\u79cd\u7279\u6b8a\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u7528\u4e8e\u652f\u6301\u6587\u672c\u641c\u7d22\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5728\u6587\u672c\u6570\u636e\u4e2d\u5feb\u901f\u67e5\u627e\u5305\u542b\u7279\u5b9a\u5173\u952e\u8bcd\u7684\u6587\u6863\u3002<\/p>\n<h2 id=\"%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bd%bf%e7%94%a8%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95%ef%bc%9f-ioHqnSclJi\">\u4e3a\u4ec0\u4e48\u4f7f\u7528\u6587\u672c\u7d22\u5f15\uff1f<\/h2>\n<p>\u5728\u5904\u7406\u5927\u91cf\u6587\u672c\u6570\u636e\u65f6\uff0c\u4f7f\u7528\u6587\u672c\u7d22\u5f15\u53ef\u4ee5\u63d0\u9ad8\u641c\u7d22\u7684\u6548\u7387\u548c\u51c6\u786e\u6027\u3002\u76f8\u6bd4\u4e8e\u4f20\u7edf\u7684\u5168\u6587\u641c\u7d22\u65b9\u6cd5\uff0c\u6587\u672c\u7d22\u5f15\u53ef\u4ee5\u66f4\u5feb\u5730\u627e\u5230\u5339\u914d\u7684\u6587\u6863\uff0c\u5e76\u4e14\u652f\u6301\u66f4\u590d\u6742\u7684\u67e5\u8be2\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%88%9b%e5%bb%ba%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95%ef%bc%9f-ioHqnSclJi\">\u5982\u4f55\u521b\u5efa\u6587\u672c\u7d22\u5f15\uff1f<\/h2>\n<p>\u5728MongoDB\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528createIndex\u65b9\u6cd5\u6765\u521b\u5efa\u6587\u672c\u7d22\u5f15\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code>db.collection.createIndex({ content: \"text\" })<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u5728\u540d\u4e3acollection\u7684\u96c6\u5408\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3acontent\u7684\u5b57\u6bb5\u7684\u6587\u672c\u7d22\u5f15\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95%e8%bf%9b%e8%a1%8c%e6%90%9c%e7%b4%a2%ef%bc%9f-ioHqnSclJi\">\u5982\u4f55\u4f7f\u7528\u6587\u672c\u7d22\u5f15\u8fdb\u884c\u641c\u7d22\uff1f<\/h2>\n<p>\u4e00\u65e6\u521b\u5efa\u4e86\u6587\u672c\u7d22\u5f15\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528$text\u64cd\u4f5c\u7b26\u6765\u8fdb\u884c\u641c\u7d22\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code>db.collection.find({ $text: { $search: \"\u5173\u952e\u8bcd\" } })<\/code><\/pre>\n<p>\u4e0a\u8ff0\u4ee3\u7801\u5c06\u5728\u540d\u4e3acollection\u7684\u96c6\u5408\u4e2d\u641c\u7d22\u5305\u542b\u5173\u952e\u8bcd\u7684\u6587\u6863\u3002<\/p>\n<h2 id=\"%e6%96%87%e6%9c%ac%e7%b4%a2%e5%bc%95%e7%9a%84%e9%99%90%e5%88%b6-ioHqnSclJi\">\u6587\u672c\u7d22\u5f15\u7684\u9650\u5236<\/h2>\n<p>\u867d\u7136\u6587\u672c\u7d22\u5f15\u5728\u5904\u7406\u6587\u672c\u6570\u636e\u65f6\u975e\u5e38\u6709\u7528\uff0c\u4f46\u4e5f\u6709\u4e00\u4e9b\u9650\u5236\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u6587\u672c\u7d22\u5f15\u53ea\u80fd\u7528\u4e8e\u5b57\u7b26\u4e32\u5b57\u6bb5\u3002<\/li>\n<li>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6587\u672c\u7d22\u5f15\u4e0d\u4f1a\u5305\u542b\u5355\u4e2a\u5b57\u7b26\u548c\u505c\u7528\u8bcd\uff08\u5982\u201c\u7684\u201d\uff0c\u201c\u662f\u201d\u7b49\uff09\u3002\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6765\u4fee\u6539\u8fd9\u4e9b\u8bbe\u7f6e\u3002<\/li>\n<li>\u6587\u672c\u7d22\u5f15\u4e0d\u652f\u6301\u6392\u5e8f\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%80%bb%e7%bb%93-ioHqnSclJi\">\u603b\u7ed3<\/h2>\n<p>\u6587\u672c\u7d22\u5f15\u662fMongoDB\u4e2d\u4e00\u79cd\u7528\u4e8e\u652f\u6301\u6587\u672c\u641c\u7d22\u7684\u7279\u6b8a\u7d22\u5f15\u7c7b\u578b\u3002\u5b83\u53ef\u4ee5\u63d0\u9ad8\u641c\u7d22\u7684\u6548\u7387\u548c\u51c6\u786e\u6027\uff0c\u5e2e\u52a9\u6211\u4eec\u5728\u5904\u7406\u5927\u91cf\u6587\u672c\u6570\u636e\u65f6\u5feb\u901f\u627e\u5230\u5339\u914d\u7684\u6587\u6863\u3002\u4f7f\u7528MongoDB\u7684\u6587\u672c\u7d22\u5f15\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u5168\u6587\u641c\u7d22\u548c\u590d\u6742\u7684\u67e5\u8be2\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e9%a6%99%e6%b8%af%e6%9c%8d%e5%8a%a1%e5%99%a8%e9%a6%96%e9%80%89%e5%90%8e%e6%b5%aa%e4%ba%91-ioHqnSclJi\">\u9999\u6e2f\u670d\u52a1\u5668\u9996\u9009\u540e\u6d6a\u4e91<\/h2>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5bfb\u627e\u53ef\u9760\u7684\u9999\u6e2f\u670d\u52a1\u5668\u63d0\u4f9b\u5546\uff0c\u540e\u6d6a\u4e91\u662f\u60a8\u7684\u9996\u9009\u3002\u6211\u4eec\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u9999\u6e2f\u670d\u52a1\u5668\uff0c\u786e\u4fdd\u60a8\u7684\u7f51\u7ad9\u548c\u5e94\u7528\u7a0b\u5e8f\u5728\u9999\u6e2f\u5730\u533a\u62e5\u6709\u5353\u8d8a\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002\u8bf7\u8bbf\u95ee\u6211\u4eec\u7684\u5b98\u7f51\u4e86\u89e3\u66f4\u591a\u4fe1\u606f\uff1a<a href=\"https:\/\/idc.net\">https:\/\/idc.net<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MongoDB \u672f\u8bed - \u6587\u672c\u7d22\u5f15 MongoDB \u672f\u8bed - \u6587\u672c\u7d22\u5f15 \u4ec0\u4e48\u662f\u6587\u672c\u7d22\u5f15\uff1f \u6587\u672c\u7d22\u5f15\u662fMongo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7038],"tags":[],"class_list":["post-247368","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/247368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=247368"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/247368\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=247368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=247368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=247368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}