1数据导出: mongoexport
语法:
mongoexport -d dbname -c collectionname -o file --type json/csv -f field
参数说明:
-d :数据库名
-c :collection名
-o :输出的文件名
--type : 输出的格式,默认为json
-f :输出的字段,如果-type为csv,则需要加上-f "字段名"
示例:
导出成json:
mongoexport -d mongotest -c users -o d:/Chromedowload/test.json --type json
导出成csv:
mongoexport -d taobao -c product -o D:\Chromedowload\taobao.csv --type csv -f "_id,image,price,deal,title,shop,lacation"
经常是需要验证的情况:
mongoexport -h=47.103.114.xxxx:27017 -uroot -pxxxx --authenticationDatabase=admin -d CFF -c my_ids -o D:\cs_ids.csv --type csv -f "id0,id1,id2"
2数据导入:
mongoimport
语法:
mongoimport -d dbname -c collectionname --file filename --headerline --type json/csv -f field
参数说明:
-d :数据库名
-c :collection名
--type :导入的格式默认json
-f :导入的字段名
--headerline :如果导入的格式是csv,则可以使用第一行的标题作为导入的字段
--file :要导入的文件
示例:
导入json:
mongoimport -d taobao -c product --file d:/Chromedowload/test.json --type json
导入csv:
mongoimport -d taobao -c new_product --type csv --headerline --file D:\Chromedowload\tbtest.csv