{"id":3891,"date":"2019-02-20T15:35:05","date_gmt":"2019-02-20T07:35:05","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3891"},"modified":"2019-02-20T15:35:05","modified_gmt":"2019-02-20T07:35:05","slug":"mongodb-%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e3%80%81%e8%bf%81%e7%a7%bb%e3%80%81%e6%81%a2%e5%a4%8d%e3%80%81%e8%bf%98%e5%8e%9f%e3%80%81%e5%af%bc%e5%85%a5%e3%80%81%e5%af%bc%e5%87%ba%e6%95%99","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3891","title":{"rendered":"MongoDB \u6570\u636e\u5e93\u5907\u4efd\u3001\u8fc1\u79fb\u3001\u6062\u590d\u3001\u8fd8\u539f\u3001\u5bfc\u5165\u3001\u5bfc\u51fa\u6559\u7a0b"},"content":{"rendered":"<p>\n\t\u5fae\u670d\u52a1\u5c31\u50cf\u4e00\u4e2a\u98ce\u53e3\uff0cNoSQL \u4e5f\u50cf\u4e00\u4e2a\u98ce\u53e3\u3002\u5927\u5bb6\u90fd\u5f00\u59cb\u63a2\u7d22\u548c\u5c1d\u8bd5\u4f7f\u7528\u5b83\u4eec\uff0c\u4f46\u662f\u90fd\u6709\u9762\u4e34\u4e00\u4e2a\u5347\u7ea7\u8fc1\u79fb\u7684\u96be\u9898\u3002\n<\/p>\n<p>\n\t\u6700\u8fd1\u6211\u4eec\u516c\u53f8\u5728\u9762\u5411\u7528\u6237\u7684\u7535\u5546\u7cfb\u7edf\uff0c\u968f\u7740\u7528\u6237\u8d8a\u6765\u8d8a\u591a\uff0c\u4e0d\u5f97\u5df2\u9700\u8981\u5bf9\u6574\u4e2a MongoDB \u6570\u636e\u5e93\u8fdb\u884c\u4e00\u6b21\u8f83\u5927\u7684\u5347\u7ea7\u3002\u800c\u8fd9\u6b21\u5347\u7ea7\u6211\u4eec\u5bf9\u91cd\u8981\u6570\u636e\u8fdb\u884c\u4e86\u6570\u636e\u8fc1\u79fb\uff0c\u5bf9\u65b0\u7cfb\u7edf\u8fdb\u884c\u652f\u6301\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"Mongo \u5907\u4efd\u4e0e\u8fd8\u539f\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g0cx6hadsfj208y05vaac.jpg\" style=\"width: 322px;height: 211px\" \/>\n<\/p>\n<p>\n\t\u5173\u4e8e\u6211\u4eec\u662f\u600e\u4e48\u8fc1\u79fb\u7684\uff0c\u6211\u53e6\u6709\u5176\u4ed6\u6587\u7ae0\u56de\u6765\u5199\u3002\u672c\u6587\uff0c\u6211\u4eec\u4e3b\u8981\u5b66\u4e60\u4e00\u4e0b\uff0cMongoDB \u4e2d\u5982\u4f55\u5907\u4efd\u3001\u8fd8\u539f\u3001\u5bfc\u5165\u3001\u5bfc\u51fa\u6570\u636e\u5e93\u548c\u6570\u636e\u8868\u3002\n<\/p>\n<h2>\n\tmongodb \u5907\u4efd<br \/>\n<\/h2>\n<p>\n\t\u5907\u4efd\u6211\u4eec\u4e00\u822c\u4f7f\u7528 mongodump \u547d\u4ee4\u3002\u5e38\u7528\u7684\u5907\u4efd\u547d\u4ee4\u683c\u5f0f\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nmongodump -h IP --port \u7aef\u53e3 -u \u7528\u6237\u540d -p \u5bc6\u7801 -d \u6570\u636e\u5e93 -o \u6587\u4ef6\u5b58\u5728\u8def\u5f84<\/pre>\n<p>\n\t\u5982\u679c\u60f3\u5bfc\u51fa\u6240\u6709\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u53bb\u6389 -d\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\nmongodump -h 127.0.0.1 --port 8888 -d xttblog -uxttblog -pxttblog -o home\/mongodb\/<\/pre>\n<h2>\n\t\u8fd8\u539f mongodb \u6570\u636e\u5e93<br \/>\n<\/h2>\n<p>\n\tMongoDB \u6570\u636e\u5e93\u8fd8\u539f\u6570\u636e\u7684\u547d\u4ee4\u683c\u5f0f\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nmongorestore -h IP --port \u7aef\u53e3 -u \u7528\u6237\u540d -p \u5bc6\u7801 -d \u6570\u636e\u5e93 --drop \u6587\u4ef6\u5b58\u5728\u8def\u5f84<\/pre>\n<p>\n\t\u4e0b\u9762\u770b\u4e00\u4e2a\u8fd8\u539f Mongo \u6570\u636e\u5e93\u7684\u64cd\u4f5c\u6848\u4f8b\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\n#xttblog \u662f\u8fd9\u4e2a\u6570\u636e\u5e93\u7684\u5907\u4efd\u8def\u5f84\r\nmongorestore -d test \/home\/mongodb\/xttblog<\/pre>\n<p>\n\t\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cmongodump \u548c mongorestore \u4e24\u4e2a\u547d\u4ee4\u64cd\u4f5c\u6587\u4ef6\u7684\u683c\u5f0f\u662f\u548c json \u7c7b\u4f3c\u7684 bson \u683c\u5f0f\u3002\n<\/p>\n<h2>\n\tMongo \u5bfc\u51fa\u8868<br \/>\n<\/h2>\n<p>\n\tMongoDB \u5bfc\u51fa\u8868\u6216\u8005\u8868\u4e2d\u90e8\u5206\u5b57\u6bb5\u7684\u547d\u4ee4\u662f\uff1amongoexport\u3002\u5e38\u7528\u5bfc\u51fa\u8868\u7684\u547d\u4ee4\u683c\u5f0f\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nmongoexport -h IP --port \u7aef\u53e3 -u \u7528\u6237\u540d -p \u5bc6\u7801 -d \u6570\u636e\u5e93 -c \u8868\u540d -f \u5b57\u6bb5<\/pre>\n<p>\n\t\u4e0a\u9762\u547d\u4ee4\u683c\u5f0f\u7684\u5404\u53c2\u6570\u4ecb\u7ecd\u5982\u4e0b\uff1a\n<\/p>\n<ul>\n<li>\n\t\t-o\uff1a\u6307\u5b9a\u6587\u4ef6\u540d\n\t<\/li>\n<li>\n\t\t-f\uff1a\u5bfc\u51fa\u6307\u5b9a\u5b57\u6bb5\uff0c\u4ee5\u5b57\u53f7\u5206\u5272\uff0c-f name,email,age \u5bfc\u51fa name,email,age \u8fd9\u4e09\u4e2a\u5b57\u6bb5\n\t<\/li>\n<li>\n\t\t-q\uff1a\u53ef\u4ee5\u6839\u67e5\u8be2\u6761\u4ef6\u5bfc\u51fa\uff0c-q &#039;{ &quot;_id&quot; : &quot;10001&quot; }&#039; \u5bfc\u51fa oid \u4e3a 10001 \u7684\u6570\u636e\n\t<\/li>\n<li>\n\t\t&#8211;csv\uff1a\u8868\u793a\u5bfc\u51fa\u7684\u6587\u4ef6\u683c\u5f0f\u4e3a csv \u7684\uff0c\u8fd9\u4e2a\u6bd4\u8f83\u6709\u7528\uff0c\u56e0\u4e3a\u5927\u90e8\u5206\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u90fd\u662f\u652f\u6301 csv\n\t<\/li>\n<\/ul>\n<p>\n\t\u4e0b\u9762\u770b\u4e24\u4e2a\u6211\u5bfc\u51fa\u7684\u6848\u4f8b\u3002\n<\/p>\n<pre class=\"brush:bash;\">\r\n#\u5bfc\u51fa\u6574\u5f20\u8868\u3001\u6574\u4e2a\u96c6\u5408\r\nmongoexport -d xttblog -c users -o \/home\/mongodb\/xttblog\/users.dat\r\n#\u5bfc\u51fa\u8868\u4e2d\u90e8\u5206\u5b57\u6bb5\r\nmongoexport -d xttblog -c users --csv -f uid,name,sex -o xttblog\/users.csv\r\n#\u6839\u636e\u6761\u4ef6\u5bfc\u51fa\u6570\u636e\r\nmongoexport -d xttblog -c users -q &#039;{uid:{$gt:1}}&#039; -o xttblog\/users.json<\/pre>\n<h2>\n\tMongo \u5bfc\u5165\u8868<br \/>\n<\/h2>\n<p>\n\t\u6709\u5bfc\u51fa\u5c31\u6709\u5bfc\u5165\u3002\u5bfc\u5165\uff0c\u6211\u4eec\u4f7f\u7528 mongoimport \u547d\u4ee4\u3002mongoimport \u53ef\u4ee5\u5bfc\u5165\u8868\uff0c\u6216\u8005\u8868\u4e2d\u7684\u90e8\u5206\u5b57\u6bb5\u3002\n<\/p>\n<p>\n\t\u8fd8\u539f\u6574\u8868\u5bfc\u51fa\u7684\u975e csv \u6587\u4ef6\u7684\u547d\u4ee4\u683c\u5f0f\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nmongoimport -h IP --port \u7aef\u53e3 -u \u7528\u6237\u540d -p \u5bc6\u7801 -d \u6570\u636e\u5e93 -c \u8868\u540d --upsert --drop \u6587\u4ef6\u540d<\/pre>\n<p>\n\t&#8211;upsert \u53c2\u6570\u7684\u4f5c\u7528\u662f\u63d2\u5165\u6216\u8005\u66f4\u65b0\u73b0\u6709\u6570\u636e\u3002\n<\/p>\n<p>\n\t\u8fd8\u539f\u90e8\u5206\u5b57\u6bb5\u7684\u5bfc\u51fa\u6587\u4ef6\u683c\u5f0f\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nmongoimport -h IP --port \u7aef\u53e3 -u \u7528\u6237\u540d -p \u5bc6\u7801 -d \u6570\u636e\u5e93 -c \u8868\u540d --upsertFields \u5b57\u6bb5 --drop \u6587\u4ef6\u540d<\/pre>\n<p>\n\t&#8211;upsertFields \u53c2\u6570\u548c &#8211;upsert \u7c7b\u4f3c\u3002\n<\/p>\n<p>\n\t\u8fd8\u539f\u5bfc\u51fa\u7684csv\u6587\u4ef6\u683c\u5f0f\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\nmongoimport -h IP --port \u7aef\u53e3 -u \u7528\u6237\u540d -p \u5bc6\u7801 -d \u6570\u636e\u5e93 -c \u8868\u540d --type \u7c7b\u578b --headerline --upsert --drop \u6587\u4ef6\u540d<\/pre>\n<p>\n\t\u4f7f\u7528\u6848\u4f8b\u5982\u4e0b\uff1a\n<\/p>\n<pre class=\"brush:bash;\">\r\n#\u8fd8\u539f\u5bfc\u51fa\u7684\u8868\u6570\u636e\r\nmongoimport -d xttblog -c users --upsert xttblog\/users.dat\r\n#\u90e8\u5206\u5b57\u6bb5\u7684\u8868\u6570\u636e\u5bfc\u5165\r\nmongoimport -d xttblog -c users  --upsertFields uid,name,sex  xttblog\/users.dat\r\n#\u8fd8\u539fcsv\u6587\u4ef6\r\nmongoimport -d xttblog -c users --type csv --headerline --file xttblog\/users.csv<\/pre>\n<p>\n\t\u4ee5\u4e0a\u5e0c\u671b\u80fd\u5bf9\u5927\u5bb6\u6709\u6240\u5e2e\u52a9\u3002\u5982\u6709\u7591\u95ee\uff0c\u53ef\u4ee5\u901a\u8fc7\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7\u8054\u7cfb\u6211\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3891\">MongoDB \u6570\u636e\u5e93\u5907\u4efd\u3001\u8fc1\u79fb\u3001\u6062\u590d\u3001\u8fd8\u539f\u3001\u5bfc\u5165\u3001\u5bfc\u51fa\u6559\u7a0b<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5fae\u670d\u52a1\u5c31\u50cf\u4e00\u4e2a\u98ce\u53e3\uff0cNoSQL \u4e5f\u50cf\u4e00\u4e2a\u98ce\u53e3\u3002\u5927\u5bb6\u90fd\u5f00\u59cb\u63a2\u7d22\u548c\u5c1d\u8bd5\u4f7f\u7528\u5b83\u4eec\uff0c\u4f46\u662f\u90fd\u6709\u9762\u4e34\u4e00\u4e2a\u5347\u7ea7\u8fc1\u79fb\u7684\u96be\u9898\u3002  [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[70,1578,523,859],"class_list":["post-3891","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-java","tag-mongodb","tag-523","tag-859"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3891"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3891\/revisions"}],"predecessor-version":[{"id":3892,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3891\/revisions\/3892"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}