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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM