mongo导入导出

MongoDB的bin目录下提供了一个mongoexport.exe的程序,可以用于导出数据。

使用$ mongoexport --help 可以查看相关参数的说明:

$ mongoexport --help
Export mongodb data to CSV, TSV or JSON files.

Options:
  --help                                produce help message
 --quiet                               silence all non error diagnostic  messages 
  -h [ --host ] arg                     mongo host to connect to ( <set name>/s1,s2 for sets)  主机名 默认127.0.0.1
  --port arg                            server port. Can also use --host hostname:port  端口 默认27017
  -u [ --username ] arg                 username 用户名
  -p [ --password ] arg                 password 密码

  -d [ --db ] arg                       database to use 数据库

  -c [ --collection ] arg               collection to use (some commands)  集合名
  -f [ --fields ] arg                   comma separated list of field names  e.g. -f name,age 字段名,导出到csv时候需要
  --fieldFile arg                       file with field names - 1 per line
  --csv                                 export to csv instead of json  导出csv格式
  -o [ --out ] arg                      output file; if not specified, stdout  is used 导出文件名

  -q [ --query ] arg                    query filter, as a JSON string, e.g., '{x:{$gt:1}}'  查询条件,使用json格式

  --skip arg (=0)                       documents to skip, default 0  跳过数据,偏移,默认为0
  --limit arg (=0)                      limit the numbers of documents returned, default all 限制返回的documents数量,默认为0

  --sort arg                            sort order, as a JSON string, e.g.,  '{x:1}' 排序


mongoexport -port 2717 -u cache -p ffcsict389 --csv -f Nme,_id,fCd,fLt,fcr -d cache -c t_function -o  /home/mongo/mongodb/cache_date_file/t_function.csv
mongoexport -port 2717 -u cache -p ffcsict389 --csv -f Nme,_id,fCd,fLt,fcr,servid -d cache -c t_function_cur -o  /home/mongo/mongodb/cache_date_file/t_function_cur.csv
mongoexport -port 2717 -u cache -p ffcsict389 --csv -f _id,msgid,msgn,url -d cache -c t_msgdic -o  /home/mongo/mongodb/cache_date_file/t_msgdic.csv
mongoexport -port 2717 -u cache -p ffcsict389 --csv -f _id,Nme,Pwd,fLt,fcr,cId,sQN,pQN,nme,pwd -d cache -c t_platform -o  /home/mongo/mongodb/cache_date_file/t_platform.csv




 进入mongo bin目录执行:./mongoimport -h localhost:2717  -d imp -c enpoints  --type csv --headerline  -file /home/WsxcdE1/files/inmongo3.csv 
   -h 连接地址,如果默认27017端口则不用
   -d 数据库
   -c 表名
   --type 文件类型
   --headerline 指明第一行是列名,不需要导入
   -file 文件路径

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值