{"id":445,"date":"2020-05-07T16:30:59","date_gmt":"2020-05-07T08:30:59","guid":{"rendered":"https:\/\/blog.humh.cn\/?p=445"},"modified":"2020-05-07T16:34:11","modified_gmt":"2020-05-07T08:34:11","slug":"mongodb-%e6%95%b0%e6%8d%ae%e5%af%bc%e5%87%ba%e5%8f%8a%e5%af%bc%e5%85%a5","status":"publish","type":"post","link":"https:\/\/blog.humh.cn\/?p=445","title":{"rendered":"MongoDB \u6570\u636e\u5bfc\u51fa\u53ca\u5bfc\u5165"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>\u8bb0\u5f55\u4e00\u4e0b\uff0c\u5982\u4f55\u5c06MongoDB\u4e2d\u7684\u67d0\u4e2a\u5e93\u6570\u636e\u5bfc\u5165\u5230\u53e6\u5916\u4e00\u4e2a\u4e3b\u673a\u7684MongoDB\u5e93\u4e2d\u3002<\/p><\/blockquote>\n\n\n\n<p><strong>MongoDB\u81ea\u8eab\u652f\u6301\u6570\u636e\u7684\u5bfc\u5165\u548c\u5bfc\u51fa\uff0c\u4e0d\u9700\u8981\u989d\u5916\u7ec4\u4ef6\uff0c\u5b89\u88c5\u4e86MongoDB\u5373\u53ef<\/strong>\u3002\u5728 MongoDB\u76ee\u5f55\u4e0b\u5b58\u5728<strong>mongoexport.exe<\/strong>\u548c<strong>mongoimport.exe<\/strong>\u6587\u4ef6 \uff0c\u8fd9\u4e24\u4e2a\u6587\u4ef6\u5206\u522b\u5b9e\u73b0\u5bfc\u51fa\u548c\u5bfc\u5165\u3002<\/p>\n\n\n\n<h4>\u6570\u636e\u5bfc\u51fa<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mongoexport -h dbhost -u \u201cusername\u201d -p \u201cpassword\u201d -d dbName -c collectionName --type json\/csv -f fields -o filename<\/pre>\n\n\n\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul><li><strong>-h<\/strong>\uff1a\u9700\u8981\u6570\u636e\u5bfc\u51fa\u7684MongoDB\u670d\u52a1\u5730\u5740\uff0c\u53ef\u6307\u5b9a\u7aef\u53e3\u53f7\uff0c\u5982\u4e0d\u6307\u5b9a\uff0c\u5219\u9ed8\u8ba4MongoDB\u7aef\u53e3\u53f7\u3002\u4e0d\u6307\u5b9a-h\uff0c\u5219\u9ed8\u8ba4127.0.0.1\u3002<\/li><li><strong>-u<\/strong>\uff1aMongoDB \u7528\u6237\u540d\uff0c\u5982\u679c\u5f00\u542f\u4e86\u6743\u9650\u8ba4\u8bc1\u7684\u8bdd\u3002<\/li><li><strong>-p<\/strong>\uff1aMongoDB \u5bc6\u7801\uff0c\u5982\u679c\u5f00\u542f\u4e86\u6743\u9650\u8ba4\u8bc1\u7684\u8bdd\u3002<\/li><li><strong>-d<\/strong>\uff1a\u9700\u8981\u6570\u636e\u5bfc\u51fa\u7684 MongoDB \u67d0\u4e2a\u5e93\uff0c\u5e93\u540d\u3002<\/li><li><strong>-c<\/strong>\uff1a\u96c6\u5408\u540d\uff0cMongoDB\u67d0\u4e2a\u5e93\u7684\u201c\u67d0\u5f20\u8868\u540d\u201d\u3002<\/li><li><strong>&#8211;type<\/strong>\uff1a\u5c06\u6570\u636e\u4ee5\u54ea\u79cd\u683c\u5f0f\u5bfc\u51fa\uff0c\u652f\u6301json\u548ccsv\u3002\u4e0d\u6307\u5b9a\u9ed8\u8ba4json<\/li><li><strong>-f<\/strong>\uff1a\u9700\u8981\u5bfc\u51fa\u5177\u4f53\u96c6\u5408\uff08\u201c\u8868\u201d\uff09\u4e2d\u7684\u54ea\u4e2a\u5b57\u6bb5\u7684\u6570\u636e\u3002\u4e0d\u6307\u5b9a\u9ed8\u8ba4\u96c6\u5408\u5168\u90e8\u5b57\u6bb5\u3002<\/li><li><strong>-o<\/strong>\uff1a\u5bfc\u51fa\u81f3\u54ea\u4e2a\u6587\u4ef6\u4e2d\uff0c\u5373\u5bfc\u51fa\u540e\u7684\u6587\u4ef6\u540d\u3002\u6570\u636e\u5bfc\u51fa\uff0c\u81ea\u52a8\u521b\u5efa\u751f\u6210\u3002<\/li><\/ul>\n\n\n\n<p>\u8fd9\u91cc\uff0c\u6211\u9700\u8981\u5bfc\u51fa\u672c\u5730MongoDB\u4e2dmydb\u5e93\uff08\u6ca1\u6709\u5f00\u542f\u8ba4\u8bc1\uff09\u4e2d\u7684test\u96c6\u5408\u7684\u6240\u6709\u6570\u636e\uff0c\u5bfc\u51fa\u4e3a\u6839\u4e0b\u7684test.json\u6587\u4ef6\uff0c\u5219\uff1a<code>mongoexport -d mydb -c test --type json  -o \/test.json<\/code><\/p>\n\n\n\n<h4>\u6570\u636e\u5bfc\u5165<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mongoimport -h dbhost -u \u201cusername\u201d -p \u201cpassword\u201d -d dbName -c collectionName --type json\/csv -f fields --file filename<\/pre>\n\n\n\n<ul><li><strong>-h<\/strong>\uff1a\u9700\u8981\u6570\u636e\u5bfc\u5165\u7684MongoDB\u670d\u52a1\u5730\u5740\uff0c\u53ef\u6307\u5b9a\u7aef\u53e3\u53f7\uff0c\u5982\u4e0d\u6307\u5b9a\uff0c\u5219\u9ed8\u8ba4MongoDB\u7aef\u53e3\u53f7\u3002\u4e0d\u6307\u5b9a-h\uff0c\u5219\u9ed8\u8ba4127.0.0.1\u3002<\/li><li><strong>-u<\/strong>\uff1aMongoDB \u7528\u6237\u540d\uff0c\u5982\u679c\u5f00\u542f\u4e86\u6743\u9650\u8ba4\u8bc1\u7684\u8bdd\u3002<\/li><li><strong>-p<\/strong>\uff1aMongoDB \u5bc6\u7801\uff0c\u5982\u679c\u5f00\u542f\u4e86\u6743\u9650\u8ba4\u8bc1\u7684\u8bdd\u3002<\/li><li><strong>-d<\/strong>\uff1a\u9700\u8981\u6570\u636e\u5bfc\u5165\u81f3MongoDB \u67d0\u4e2a\u5e93\uff0c\u5e93\u540d\u3002<\/li><li><strong>-c<\/strong>\uff1a\u96c6\u5408\u540d\uff0cMongoDB\u67d0\u4e2a\u5e93\u7684\u201c\u67d0\u5f20\u8868\u540d\u201d\u3002<\/li><li><strong>&#8211;type<\/strong>\uff1a\u5c06\u6570\u636e\u4ee5\u54ea\u79cd\u683c\u5f0f\u5bfc\u5165\u89e3\u6790\uff0c\u652f\u6301json\u548ccsv\u3002\u4e0d\u6307\u5b9a\u9ed8\u8ba4json<\/li><li><strong>-f<\/strong>\uff1a\u9700\u8981\u5bfc\u5165\u5177\u4f53\u96c6\u5408\uff08\u201c\u8868\u201d\uff09\u4e2d\u7684\u54ea\u4e2a\u5b57\u6bb5\u7684\u6570\u636e\u3002\u4e0d\u6307\u5b9a\u9ed8\u8ba4\u96c6\u5408\u5168\u90e8\u5b57\u6bb5\u3002<\/li><li><strong>&#8211;file<\/strong>\uff1a\u5bfc\u5165\u54ea\u4e2a\u6587\u4ef6\uff0c\u5373\u4ece\u54ea\u4e2a\u6587\u4ef6\u5bfc\u5165\u89e3\u6790\u6570\u636e\u3002<\/li><\/ul>\n\n\n\n<p>\u8fd9\u91cc\uff0c\u6211\u9700\u8981\u5c06\u201c\/test.json\u201d\u6570\u636e\u5bfc\u5165\u81f3\u672c\u5730MongoDB\u7684mydb\u5e93\uff08\u672a\u5f00\u542f\u6743\u9650\u8ba4\u8bc1\uff09\u4e2d\u7684test\u96c6\u5408\uff0c\u5219\uff1a<code>mongoimport -d mydb -c test --type json --file \/test.json<\/code><\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<p>\u5f53\u7136\uff0c\u5bfc\u5165\u5bfc\u51fa\u547d\u4ee4\uff0c\u8fd8\u6709\u5176\u4ed6\u53c2\u6570\uff0c\u53ef\u4ee5\u8fdb\u884c\u66f4\u7ec6\u81f4\u7684\u64cd\u4f5c\uff0c\u5177\u4f53\u53ef\u53c2\u8003\u5b98\u65b9\u6587\u6863\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bb0\u5f55\u4e00\u4e0b\uff0c\u5982\u4f55\u5c06MongoDB\u4e2d\u7684\u67d0\u4e2a\u5e93\u6570\u636e\u5bfc\u5165\u5230\u53e6\u5916\u4e00\u4e2a\u4e3b\u673a\u7684MongoDB\u5e93\u4e2d\u3002 MongoDB\u81ea\u8eab\u652f\u6301\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[72],"tags":[71],"_links":{"self":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/445"}],"collection":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=445"}],"version-history":[{"count":4,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/445\/revisions"}],"predecessor-version":[{"id":451,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=\/wp\/v2\/posts\/445\/revisions\/451"}],"wp:attachment":[{"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=445"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=445"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.humh.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=445"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}