zoukankan      html  css  js  c++  java
  • 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
     
  • 相关阅读:
    北斗授时服务器,时间同步服务器,网络时钟服务器2020最新报价
    北斗GPS卫星同步时钟让采集系统更精准
    ntp时钟服务器(医院时钟系统)在网络里的作用
    「Excel技巧」Excel中根据某列的值去汇总另外一列的值
    「Excel技巧」Excel技巧之如何看文件里的宏?
    「杂谈」同学聚会最悲哀的事情
    torch 中的损失函数
    CJJ/T 302-2019 城市园林绿化监督管理信息系统工程技术标准
    SJ/T 11362-2006 企业信息化技术规范 制造执行系统(MES)规范
    1. C语言三个数从小到大排序/输出
  • 原文地址:https://www.cnblogs.com/lingwang3/p/6567857.html
Copyright © 2011-2022 走看看