{"id":63940,"date":"2024-10-14T03:46:16","date_gmt":"2024-10-13T19:46:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/63940\/"},"modified":"2024-10-14T03:46:16","modified_gmt":"2024-10-13T19:46:16","slug":"mongodb%e6%95%b8%e6%93%9a%e5%ba%ab%e8%bd%89%e6%8f%9b%e7%82%ba%e8%a1%a8%e6%a0%bc%e6%96%87%e4%bb%b6%e7%9a%84%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/63940\/","title":{"rendered":"Mongodb\u6578\u64da\u5eab\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\u7684\u5eab"},"content":{"rendered":"<h1 id=\"mongodb%e6%95%b8%e6%93%9a%e5%ba%ab%e8%bd%89%e6%8f%9b%e7%82%ba%e8%a1%a8%e6%a0%bc%e6%96%87%e4%bb%b6%e7%9a%84%e5%ba%ab-DPQpFEDRtD\">MongoDB\u6578\u64da\u5eab\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\u7684\u5eab<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u9078\u64c7\u548c\u7ba1\u7406\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002MongoDB\u4f5c\u70ba\u4e00\u7a2e\u6d41\u884c\u7684NoSQL\u6578\u64da\u5eab\uff0c\u56e0\u5176\u9748\u6d3b\u6027\u548c\u53ef\u64f4\u5c55\u6027\u800c\u53d7\u5230\u5ee3\u6cdb\u4f7f\u7528\u3002\u7136\u800c\uff0c\u5c07MongoDB\u4e2d\u7684\u6578\u64da\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\uff08\u5982CSV\u6216Excel\uff09\u4ee5\u4fbf\u65bc\u5206\u6790\u548c\u5831\u544a\uff0c\u537b\u5e38\u5e38\u6210\u70ba\u4e00\u500b\u6311\u6230\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u4e00\u4e9b\u6709\u6548\u7684\u5eab\u548c\u5de5\u5177\uff0c\u5e6b\u52a9\u7528\u6236\u5c07MongoDB\u6578\u64da\u5eab\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e5%b0%87mongodb%e6%95%b8%e6%93%9a%e8%bd%89%e6%8f%9b%e7%82%ba%e8%a1%a8%e6%a0%bc%e6%96%87%e4%bb%b6%ef%bc%9f-DPQpFEDRtD\">\u70ba\u4ec0\u9ebc\u9700\u8981\u5c07MongoDB\u6578\u64da\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\uff1f<\/h2>\n<p>\u5c07MongoDB\u6578\u64da\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\u7684\u539f\u56e0\u6709\u5f88\u591a\u3002\u9996\u5148\uff0c\u8868\u683c\u6587\u4ef6\u683c\u5f0f\uff08\u5982CSV\u6216Excel\uff09\u66f4\u6613\u65bc\u8207\u5176\u4ed6\u61c9\u7528\u7a0b\u5e8f\u5171\u4eab\u548c\u5206\u6790\u3002\u5176\u6b21\uff0c\u8a31\u591a\u5546\u696d\u667a\u80fd\u5de5\u5177\u548c\u6578\u64da\u5206\u6790\u5e73\u53f0\u66f4\u5bb9\u6613\u8655\u7406\u7d50\u69cb\u5316\u6578\u64da\uff0c\u9019\u4f7f\u5f97\u5c07\u6578\u64da\u8f49\u63db\u70ba\u8868\u683c\u683c\u5f0f\u8b8a\u5f97\u5fc5\u8981\u3002\u6b64\u5916\uff0c\u8868\u683c\u6587\u4ef6\u901a\u5e38\u66f4\u6613\u65bc\u95b1\u8b80\u548c\u7406\u89e3\uff0c\u7279\u5225\u662f\u5c0d\u65bc\u975e\u6280\u8853\u7528\u6236\u4f86\u8aaa\u3002<\/p>\n<h2 id=\"%e5%b8%b8%e7%94%a8%e7%9a%84mongodb%e6%95%b8%e6%93%9a%e8%bd%89%e6%8f%9b%e5%ba%ab-DPQpFEDRtD\">\u5e38\u7528\u7684MongoDB\u6578\u64da\u8f49\u63db\u5eab<\/h2>\n<h3 id=\"1-mongodb-export-tool-DPQpFEDRtD\">1. MongoDB Export Tool<\/h3>\n<p>MongoDB\u81ea\u5e36\u7684\u5c0e\u51fa\u5de5\u5177\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u8f15\u9b06\u5730\u5c07\u6578\u64da\u5c0e\u51fa\u70baCSV\u683c\u5f0f\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code>mongoexport --db yourDatabase --collection yourCollection --type=csv --fields field1,field2,field3 --out output.csv<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u5c07\u6307\u5b9a\u6578\u64da\u5eab\u548c\u96c6\u5408\u4e2d\u7684\u6578\u64da\u5c0e\u51fa\u70baCSV\u6587\u4ef6\uff0c\u4e26\u9078\u64c7\u7279\u5b9a\u7684\u5b57\u6bb5\u3002<\/p>\n<h3 id=\"2-pandas-DPQpFEDRtD\">2. Pandas<\/h3>\n<p>Pandas\u662f\u4e00\u500b\u5f37\u5927\u7684Python\u6578\u64da\u5206\u6790\u5eab\uff0c\u80fd\u5920\u8f15\u9b06\u5730\u5f9eMongoDB\u8b80\u53d6\u6578\u64da\u4e26\u5c07\u5176\u8f49\u63db\u70ba\u8868\u683c\u683c\u5f0f\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528Pandas\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>import pandas as pd\nfrom pymongo import MongoClient\n\n# \u9023\u63a5\u5230MongoDB\nclient = MongoClient('mongodb:\/\/localhost:27017\/')\ndb = client['yourDatabase']\ncollection = db['yourCollection']\n\n# \u5c07\u6578\u64da\u8f49\u63db\u70baDataFrame\ndata = pd.DataFrame(list(collection.find()))\n\n# \u5c07DataFrame\u5c0e\u51fa\u70baCSV\ndata.to_csv('output.csv', index=False)<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u9996\u5148\u9023\u63a5\u5230MongoDB\uff0c\u7136\u5f8c\u5c07\u6307\u5b9a\u96c6\u5408\u7684\u6578\u64da\u8b80\u53d6\u5230Pandas\u7684DataFrame\u4e2d\uff0c\u6700\u5f8c\u5c07\u5176\u5c0e\u51fa\u70baCSV\u6587\u4ef6\u3002<\/p>\n<h3 id=\"3-mongodb-connector-for-bi-DPQpFEDRtD\">3. MongoDB Connector for BI<\/h3>\n<p>MongoDB Connector for BI\u5141\u8a31\u7528\u6236\u4f7f\u7528SQL\u67e5\u8a62MongoDB\u6578\u64da\uff0c\u4e26\u5c07\u5176\u5c0e\u51fa\u70ba\u8868\u683c\u683c\u5f0f\u3002\u9019\u5c0d\u65bc\u9700\u8981\u4f7f\u7528SQL\u9032\u884c\u6578\u64da\u5206\u6790\u7684\u7528\u6236\u4f86\u8aaa\u975e\u5e38\u6709\u7528\u3002\u7528\u6236\u53ef\u4ee5\u901a\u904e\u9023\u63a5\u5230MongoDB\u7684BI\u5de5\u5177\uff08\u5982Tableau\u6216Power BI\uff09\u4f86\u5be6\u73fe\u9019\u4e00\u9ede\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-DPQpFEDRtD\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u5c07MongoDB\u6578\u64da\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8003\u616e\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u7d50\u69cb\uff1a<\/strong>MongoDB\u662f\u6587\u6a94\u5c0e\u5411\u7684\u6578\u64da\u5eab\uff0c\u6578\u64da\u7d50\u69cb\u53ef\u80fd\u6703\u975e\u5e38\u9748\u6d3b\uff0c\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u5728\u8f49\u63db\u904e\u7a0b\u4e2d\u51fa\u73fe\u554f\u984c\u3002\u78ba\u4fdd\u5728\u5c0e\u51fa\u4e4b\u524d\u4e86\u89e3\u6578\u64da\u7684\u7d50\u69cb\u3002<\/li>\n<li><strong>\u6027\u80fd\uff1a<\/strong>\u5c0d\u65bc\u5927\u578b\u6578\u64da\u96c6\uff0c\u5c0e\u51fa\u904e\u7a0b\u53ef\u80fd\u6703\u8017\u6642\uff0c\u5efa\u8b70\u5728\u975e\u9ad8\u5cf0\u6642\u6bb5\u9032\u884c\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u6578\u64da\u5b8c\u6574\u6027\uff1a<\/strong>\u5728\u8f49\u63db\u904e\u7a0b\u4e2d\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u6e96\u78ba\u6027\uff0c\u907f\u514d\u4e1f\u5931\u91cd\u8981\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-DPQpFEDRtD\">\u7e3d\u7d50<\/h2>\n<p>\u5c07MongoDB\u6578\u64da\u5eab\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\u662f\u4e00\u500b\u91cd\u8981\u7684\u904e\u7a0b\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u66f4\u597d\u5730\u5206\u6790\u548c\u5171\u4eab\u6578\u64da\u3002\u7121\u8ad6\u662f\u4f7f\u7528MongoDB\u81ea\u5e36\u7684\u5c0e\u51fa\u5de5\u5177\u3001Pandas\u5eab\uff0c\u9084\u662fMongoDB Connector for BI\uff0c\u9078\u64c7\u5408\u9069\u7684\u65b9\u6cd5\u90fd\u80fd\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684<code><a href=\"https:\/\/server.hk\">VPS<\/a><\/code>\u89e3\u6c7a\u65b9\u6848\u4e5f\u80fd\u63d0\u4f9b\u66f4\u597d\u7684\u652f\u6301\uff0c\u7279\u5225\u662f\u5728\u9999\u6e2f\u5730\u5340\uff0c<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u670d\u52d9\u80fd\u5920\u6eff\u8db3\u5404\u7a2e\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c07MongoDB\u6578\u64da\u5eab\u8f15\u9b06\u8f49\u63db\u70ba\u8868\u683c\u6587\u4ef6\u7684\u5eab\uff0c\u652f\u6301\u591a\u7a2e\u683c\u5f0f\uff0c\u7c21\u5316\u6578\u64da\u8655\u7406\u8207\u5206\u6790\u6d41\u7a0b\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-63940","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/63940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=63940"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/63940\/revisions"}],"predecessor-version":[{"id":63941,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/63940\/revisions\/63941"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=63940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=63940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=63940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}