{"rsdb":{"rid":"243073","subhead":"","postdate":"0","aid":"167335","fid":"77","uid":"1","topic":"1","content":"
\n

Centos\u4e0b\u901a\u8fc7yum\u5b89\u88c5\u6b65\u9aa4\u5982\u4e0b\uff1a<\/strong><\/p> \n

      \u58f0\u660e\uff1a\u76f8\u5bf9\u6bd4\u90a3\u4e9b\u7528\u6e90\u7801\u5b89\u88c5\uff0c\u5c11\u4e86\u914d\u7f6e\u548c\u65b0\u5efalog\u548cdata\u76ee\u5f55\uff0c\u8fd9\u79cd\u7b80\u5355\u7c97\u66b4\uff0c<\/span><\/p> \n

\n
1<\/span>\uff0c\u521b\u5efa\u4ed3\u5e93\u6587\u4ef6\uff0c\n      vi <\/span>\/etc\/yum.repos.d\/mongodb-org-3.4<\/span>.repo\n<\/span>2<\/span>,\u590d\u5236\u4e0b\u9762\u914d\u7f6e\uff0c\u4fdd\u5b58\u9000\u51fa\n     [mongodb<\/span>-org-3.4<\/span>]\n     name<\/span>=MongoDB Repository\n\u3000\u3000\u3000baseurl<\/span>=https:\/\/<\/span>repo.mongodb.org\/yum\/redhat\/$releasever\/mongodb-org\/3.4\/x86_64\/<\/span>\n\u3000\u3000\u3000gpgcheck=1<\/span>\n\u3000\u3000\u3000enabled<\/span>=1<\/span>\n\u3000\u3000\u3000gpgkey<\/span>=https:\/\/<\/span>www.mongodb.org\/static\/pgp\/server-3.4.asc
<\/span><\/pre> \n
 3\uff0cyum\u5b89\u88c5
yum install -y mongodb-org

4\uff0c\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u522b\u7684\u673a\u5668\u4e5f\u80fd\u8bbf\u95ee\uff0c\u4e0d\u6b62\u662f 127.0.0.1
vi \/etc\/mongod.conf -----\u300bbind_ip \u9ed8\u8ba4\u662f127.0.0.1 \u4fee\u6539\u4e3a 0.0.0.0

5\uff0c\u542f\u52a8\uff0c\u505c\u6b62
service mongo start, service mongo stop

6,\u65e5\u5fd7\u76ee\u5f55\u4f4d\u7f6e ---\u300b cat \/var\/log\/mongodb\/mongod.log
\u6570\u636e\u5e93\u6587\u4ef6 ----\u300b cat \/var\/lib\/mongo

7,\u5378\u8f7d mongo ----> yum erase $(rpm -qa | grep mongodb-org)

<\/span><\/pre> \n
\u8fde\u63a5mongo\u7684\u53ef\u89c6\u5316\u5de5\u5177\u6211\u7528\u7684\u662f--robo3T \u6ce8\u610f\u7684\u662fMongoVUE\u4e0d\u652f\u6301mongodb3\u7248\u672c\u7684<\/span><\/pre> \n <\/div> \n 

 <\/p> \n

mongodb \u5e38\u7528\u547d\u4ee4\uff1a<\/strong><\/p> \n

\n
  \u67e5\u770b\u6570\u636e\u5e93\n    <\/span>> show dbs\n  \u4f7f\u7528\u6570\u636e\u5e93\n     <\/span>> use database-name\n   \u67e5\u770b\u8868\n     <\/span>> show tables\n   \u67e5\u8be2\u6570\u636e\n      <\/span>> db.table-name.find({})\n   \u67e5\u8be2\u6761\u4ef6\n      <\/span>> db.table-name.find({'<\/span>name<\/span>'<\/span>:'<\/span>zhangsan<\/span>'<\/span>})
\u5efa\u7acb\u7d22\u5f15
> db.table-name.ensureIndex({'name':1}) 1\u4e3a\u5347\u5e8f\uff0c-1\u4e3a\u964d\u5e8f
\u590d\u5408\u7d22\u5f15
> db.table-name.ensureIndex{{'name':1,'age':1}} \u53ea\u67e5\u8be2name\u4f1a\u7d22\u5f15\u3002\u5982\u679c\u53ea\u67e5\u8be2age\u4e0d\u4f1a\u7528\u5230\u7d22\u5f15\uff0c\u5982\u679c\u60f3\u7528\u7d22\u5f15\u524d\u9762\u5fc5\u987b\u6709N\u4e2a\u7d22\u5f15\u5217
\u67e5\u770b\u7d22\u5f15\u662f\u5426\u5efa\u7acb
> db.table-name.getIndexes()
\u5220\u9664\u7d22\u5f15
> db.table-name.dropIndex({'name':1})
\u7ba1\u7406\u7d22\u5f15\uff0c\u67e5\u770b\u6240\u6709\u7d22\u5f15\uff1a
> db.system.index.find()
<\/pre> \n <\/div> \n

 <\/p> \n

mongo \u5bfc\u5165 json \u6216\u8005csv \u505a\u6cd5<\/strong><\/p> \n

\u58f0\u660e\uff1a4G\u7684 .sql\u6587\u4ef6\uff0820050144\u6761\u6570\u636e\uff09\u5bfc\u5165mongodb \u603b\u5171\u65f6\u95f4\u4e3a 28\u5206\u949f + 25\u5206\u949f + 15\u5206\u949f
\u2460\uff0c28\u5206\u949f: \u5728linux \u4e2d source .\/.sql\u76ee\u5f55 \u5bfc\u5165\u6570\u636e\u5e93
\u2461\uff0c25\u5206\u949f\uff1a \u7528Navicat for MySQL \u5bfc\u51fa\u683c\u5f0f\u4e3acsv \u6216\u8005json
\u2462\uff0c15\u5206\u949f\uff1a \u7528mongo\u81ea\u5e26\u7684mongoimport\u547d\u4ee4 \u4e0a\u4f20csv\u6216\u8005json

<\/pre> \n
\n
\u524d2\u6b65\u50bb\u74dc\u5f0f\u64cd\u4f5c\uff0c\u552f\u4e00\u6ce8\u610f\u7684\u662f\u2461\u6b65:
json\u683c\u5f0f\u60c5\u51b5\u4e0b\uff1a 4G\u5927\u5c0f\u7684.sql\u6587\u4ef6\uff0c\u5982\u679c\u7528navicat\u8f6c\u4e3ajson\u5927\u5c0f\u4e3a11G\uff0c11G\u7684json\u4e0a\u4f20mongo\u4f1a \u2018\/a\u2019\u9519\u8bef\uff0c\u5b9e\u9a8c200MB\u7684\u6ca1\u6709\u95ee\u9898
csv\u683c\u5f0f\u60c5\u51b5\u4e0b\uff1a 4G\u5927\u5c0f\u7684.sql\u6587\u4ef6\uff0c\u5982\u679c\u7528navicat\u8f6c\u4e3acsv\u5927\u5c0f\u8fd8\u662f4G\uff0c\u5176\u4e2dcsv\u4f1a\u662f\u4e71\u7801\uff0c\u4e0d\u7528\u7ba1\uff0c\u76f4\u63a5\u4e0a\u4f20mongo\u6ca1\u6709\u95ee\u9898\uff0c
navicat\u5bfc\u51fa\u7684\u65f6\u5019\u9009\u62e9\u4e00\u5b9a\u9009\u62e9 \u2019\u5305\u542b\u5217\u7684\u6807\u9898\u2018 \u540e\u671f\u4e0a\u4f20\u540dmongdb\u65f6\u5019\u53ef\u4ee5\u5c11\u586b\u5199\u53c2\u6570\u4e3a\u5217<\/pre> \n
\u5bfc\u5165\u547d\u4ee4\u5982\u4e0b\uff1a
json\uff1a <\/pre> \n
\n             \n mongoimport <\/span>--db  table-name  --collection table-name  --file \/test.json \n   <\/em><\/em>\n <\/div> \n
\n
     csv\uff1a
mongoimport<\/span> --db table-name  --collection table-name --type csv --headerline --ignoreBlanks  --file \/test.csv  --numInsertionWorkers 4<\/pre> \n
\u5bfc\u51fa\u547d\u4ee4\u5982\u4e0b\uff1a<\/pre> \n   
      json\uff1a<\/pre> \n   

            mongoexport  <\/span>--db  table-name  --collection table-name  -o \/test.json<\/p> \n

      csv\uff1a 

mongoexport<\/span>  --db  table-name  --collection table-name --csv -f id,province,city -o \/test.json
--csv \u6307\u8981\u8981\u5bfc\u51fa\u4e3acsv \u683c\u5f0f\uff0c\u5bfc\u51facsv\u4e4b\u540e\u5fc5\u987b\u6307\u660e\u5bfc\u51fa\u7684\u5217
-f \u6307\u660e\u9700\u8981\u5bfc\u51fa\u54ea\u4e9b\u5217<\/em><\/pre> \n
 
\u53c2\u6570\u8bf4\u660e
--db \u6307\u660e\u4f7f\u7528\u7684\u5e93, \u672c\u4f8b\u4e2d\u4e3a\u201d table-name<\/em><\/em>\u201d<\/em><\/em><\/em><\/pre> \n
          --collection \u6307\u660e\u8981\u5bfc\u51fa\u7684\u8868, \u672c\u4f8b\u4e2d\u4e3a\u201dtable-name\u201d
--type \u6307\u660e\u5bfc\u5165\u7684\u7c7b\u578b\uff0c\u9ed8\u8ba4\u7684\u4e3ajson
<\/em> --headerline \u4ec5\u9002\u7528\u4e8e\u5bfc\u5165csv,tsv\u683c\u5f0f\u7684\u6570\u636e\uff0c\u8868\u793a\u6587\u4ef6\u4e2d\u7684\u7b2c\u4e00\u884c\u4f5c\u4e3a\u6570\u636e\u5934
--ignoreBlanks \u5ffd\u7565\u7a7a\u767d\u7b26
--file \u6587\u4ef6\u7684\u4f4d\u7f6e
--numInsertionWorkers \u4e3a\u4e86\u63d0\u9ad8mongo\u7684\u63d2\u5165\u6548\u7387\uff0c\u91c7\u7528mongodb\u63a8\u8350\u7684\uff08numInsertionWorkers\uff09\u591a\u7ebf\u7a0b\u64cd\u4f5c\u3002\u672c\u8d28\u6765\u8bf4\uff0c\u5c31\u662f\u5c06insert\u4efb\u52a1\uff0c\u62c6\u5206\u6210\u591a\u4e2a\u7ebf\u7a0b\u6765\u505a\u3002<\/em><\/pre> \n <\/div> \n <\/div> \n







<\/pre> \n
<\/pre>\n<\/div>","orderid":"0","title":"Mongodb 3.4 + Centos6.5 \u914d\u7f6e + mysql.sql\u8f6c\u4e3acsv \u6216 json\u5bfc\u5165\u548c\u5bfc\u51faMongo \uff0864\u4f4d\u7cfb\u7edf\uff09","smalltitle":"","mid":"0","fname":"Python","special_id":"0","bak_id":"0","info":"0","hits":"975","pages":"1","comments":"0","posttime":"2017-12-25 06:07:11","list":"1514153231","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"Mongodb<\/A> 3.4<\/A> Centos6.5<\/A> \u914d\u7f6e<\/A> mysql.sql<\/A> \u8f6c\u4e3a<\/A> csv<\/A> json<\/A> \u5bfc\u5165<\/A> \u5bfc\u51fa<\/A> Mongo<\/A> 64\u4f4d<\/A> \u7cfb\u7edf<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"113.110.148.213","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"Mongodb 3.4 + Centos6.5 \u914d\u7f6e + mysql.sql\u8f6c\u4e3acsv \u6216 json\u5bfc\u5165\u548c\u5bfc\u51faMongo \uff0864\u4f4d\u7cfb\u7edf\uff09","lastview":"1713334159","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}