導出到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