{"id":5375,"date":"2024-11-14T10:25:21","date_gmt":"2024-11-14T02:25:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5375\/"},"modified":"2024-11-14T10:25:21","modified_gmt":"2024-11-14T02:25:21","slug":"mongodb%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5375\/","title":{"rendered":"mongodb\u600e\u4e48\u521b\u5efa\u6570\u636e\u5e93"},"content":{"rendered":"<blockquote><p>\n  \u5728 mongodb \u4e2d\u521b\u5efa\u6570\u636e\u5e93\u7684\u6b65\u9aa4\uff1a1. \u6253\u5f00 mongodb shell\uff1b2. \u901a\u8fc7 use \u547d\u4ee4\u6307\u5b9a\u6570\u636e\u5e93\u540d\u79f0\uff1b3. \u4f7f\u7528 db \u547d\u4ee4\u68c0\u67e5\u6570\u636e\u5e93\u662f\u5426\u5df2\u521b\u5efa\uff1b4. \u521b\u5efa\u96c6\u5408\uff08\u53ef\u9009\uff09\uff1b5. \u4f7f\u7528 show collections \u547d\u4ee4\u68c0\u67e5\u96c6\u5408\u662f\u5426\u5df2\u521b\u5efa\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052802421614171.jpg\" class=\"aligncenter\" title=\"mongodb\u600e\u4e48\u521b\u5efa\u6570\u636e\u5e93\u63d2\u56fe\" alt=\"mongodb\u600e\u4e48\u521b\u5efa\u6570\u636e\u5e93\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MongoDB \u4e2d\u521b\u5efa\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4e3a\u4e86\u5728 MongoDB \u4e2d\u521b\u5efa\u6570\u636e\u5e93\uff0c\u60a8\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u7b80\u5355\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u6253\u5f00 MongoDB Shell<\/strong><\/p>\n<p>\u4f7f\u7528\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u6253\u5f00 MongoDB Shell\uff1a<\/p>\n<pre>mongo<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 use \u547d\u4ee4<\/strong><\/p>\n<p>\u4f7f\u7528 use \u547d\u4ee4\u6307\u5b9a\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u540d\u4e3a my_db \u7684\u6570\u636e\u5e93\uff0c\u8bf7\u8f93\u5165\uff1a<\/p>\n<pre>use my_db<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u68c0\u67e5\u521b\u5efa<\/strong><\/p>\n<p>\u6267\u884c db \u547d\u4ee4\u4ee5\u68c0\u67e5\u662f\u5426\u5df2\u521b\u5efa\u6570\u636e\u5e93\uff1a<\/p>\n<pre>db<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u5e94\u663e\u793a\u60a8\u5f53\u524d\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5e94\u4e3a my_db\u3002<\/p>\n<p><strong>4. \u521b\u5efa\u96c6\u5408\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<p>\u4e00\u65e6\u521b\u5efa\u4e86\u6570\u636e\u5e93\uff0c\u60a8\u5c31\u53ef\u4ee5\u5f00\u59cb\u521b\u5efa\u96c6\u5408\uff08\u7c7b\u4f3c\u4e8e\u5173\u7cfb\u6570\u636e\u5e93\u4e2d\u7684\u8868\uff09\u3002\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a users \u7684\u96c6\u5408\uff0c\u8bf7\u8f93\u5165\uff1a<\/p>\n<pre>db.createCollection(\"users\")<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u68c0\u67e5\u96c6\u5408\u521b\u5efa<\/strong><\/p>\n<p>\u6267\u884c show collections \u547d\u4ee4\u4ee5\u68c0\u67e5\u96c6\u5408\u662f\u5426\u5df2\u521b\u5efa\uff1a<\/p>\n<pre>show collections<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u5e94\u663e\u793a\u96c6\u5408\u5217\u8868\uff0c\u5176\u4e2d\u5305\u62ec users \u96c6\u5408\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u521b\u5efa\u6570\u636e\u5e93\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 mongodb \u4e2d\u521b\u5efa\u6570\u636e\u5e93\u7684\u6b65\u9aa4\uff1a1. \u6253\u5f00 mongodb shell\uff1b2. \u901a\u8fc7 use \u547d\u4ee4\u6307\u5b9a\u6570\u636e\u5e93\u540d\u79f0\uff1b3. \u4f7f\u7528 db \u547d\u4ee4\u68c0\u67e5\u6570\u636e\u5e93\u662f\u5426\u5df2\u521b\u5efa\uff1b4. \u521b\u5efa\u96c6\u5408\uff08\u53ef\u9009\uff09\uff1b5. \u4f7f\u7528 show collections \u547d\u4ee4\u68c0\u67e5\u96c6\u5408\u662f\u5426\u5df2\u521b\u5efa\u3002 \u5982\u4f55\u5728 MongoDB \u4e2d\u521b\u5efa\u6570\u636e\u5e93 \u4e3a\u4e86\u5728 MongoDB \u4e2d\u521b\u5efa\u6570\u636e\u5e93\uff0c\u60a8\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u7b80\u5355\u7684\u6b65\u9aa4\uff1a 1. \u6253\u5f00 MongoDB Shell \u4f7f\u7528\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u6253\u5f00 MongoDB Shell\uff1a mongo \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 use \u547d\u4ee4 \u4f7f\u7528 use \u547d\u4ee4\u6307\u5b9a\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u540d\u4e3a my_db \u7684\u6570\u636e\u5e93\uff0c\u8bf7\u8f93\u5165\uff1a use my_db \u767b\u5f55\u540e\u590d\u5236 3. \u68c0\u67e5\u521b\u5efa \u6267\u884c db \u547d\u4ee4\u4ee5\u68c0\u67e5\u662f\u5426\u5df2\u521b\u5efa\u6570\u636e\u5e93\uff1a db \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\u5e94\u663e\u793a\u60a8\u5f53\u524d\u4f7f\u7528\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u5e94\u4e3a my_db\u3002 4. \u521b\u5efa\u96c6\u5408\uff08\u53ef\u9009\uff09 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5375","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5375","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5375"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5375\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5375"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5375"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5375"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}