Mongodb 导出json 和csv 格式数据

导出到json:

$ mongoexport.exe  -d TestDB -c TestCollection -o  ./test.json

导出到csv:

If you want to output CSV, you have to specify the fields in the order you want them.

$ mongoexport.exe  --csv -f _id,f1,f2,f3,f4,f5,f6,f7 -d TestDB -c TestCollection -o  ./test.csv

如果含有中文字符,打开csv文件可能会有乱码,用记事本另存成utf-8格式就好了。

 

在使用-q 查询条件过滤数据的时候,注意两边的 ’ (单引号)

当数据量很大时候,可以使用--skip 配合 --limit,限制单个文件的数据量,方便普通用户查看

 

导入到csv


mongoimport -d sina -c weibo -f _id -type csv -file test1.txt

 

另外,可以使用mongodump命令备份数据:

$ mongodump -h 127.0.0.1:27017 -d testDB -o ./data

 

posted on 2016-04-04 23:20  alex.shu  阅读(6332)  评论(0编辑  收藏  举报

导航