MongoDB数据的导入与导出

1.将mongodb数据库中的数据导出

  命令:mongoexport -h 192.168.86.127 --port 27017 -d music_backup -c qq_all -o qq_all_20170317

  命令:mongoexport -h 192.168.86.108 --port 27017 -d crawler_book_yamaxun -c yamaxun_comment_info -f _id -q '{"_id":{"$exists":true}}'  --csv -o 123

  导出工具:mongoexport

  1、概念:

     mongoDB中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件。可以通过参数指定导出的数据项,也可以根据指定的条件导出数据。

  2、语法:

     mongoexport  -h host --port port  -d dbName -c collName  -f field --type json/csv  -o file 

  参数说明:
     -h : 主机
    --port :端口号
            -d :数据库名
            -c :表名
            -o :输出的文件名
            --type : 输出的格式,默认为json
            -f :输出的字段,如果-type为csv,则需要加上-f "字段名"
    -q :输出查询条件
2.将数据导入mongodb
 
  命令:mongoimport -h 192.168.86.126 --port 27017 -d crawler_book_yamaxun -c yamaxun_comment_info --type csv --headerline -f _id --file 123
 
  导入工具:mongoimport 
 
  1、语法:
 
          mongoimport  -h host --port port -d dbName -c collName   --headerline --type json/csv -f field --file filename
 
  参数说明: 
 
     -h : 主机
    --port :端口号
            -d :数据库名
            -c :表名
            --type :导入的格式默认json
            -f :导入的字段名
            --headerline :如果导入的格式是csv,则可以使用第一行的标题作为导入的字段
            --file :要导入的文件
 
3.将数据库备份
  mongodump  --help
  命令:mongodump -h 192.168.86.159 --port 27017 -d weixin -c account_list --forceTableScan
  命令:mongodump -h 192.168.86.160 --port 27017 -d crawler_qq -c album --forceTableScan
 
4.将备份数据导入数据库
  mongorestore --help
  命令:mongorestore -h 192.168.86.160 --port 27017 --dir dump/
  命令:mongorestore -h 192.168.86.160 --port 27017 -d crawler_qq_2514 -c artist --dir dump/crawler_qq/artist.bson
 

转载于:https://www.cnblogs.com/lingwang3/p/6567857.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值