mongodb 的数据备份与还原

数据备份与还原

mongodump

mongorestore

数据导入与导出

mongoexport

--db <db>, -d <db>
使用--db选项来指定包含要导出集合的数据库名称。
--collection <collection>, -c <collection>
使用--collection选项来指定要导出的集合名称。
--type
输出格式,jsoncsv(默认值:json
--fields <field1[,field2]>, -f <field1[,field2]>
指定一个或多个需要导出的字段,多个字段导出需要使用由逗号分隔的字段列表来表示。
--out <filename> --o <filename>
输出文件;如果未指定,则使用stdout

导出 CSV:
mongoexport -d DBName -c CollectionName --type=csv --fields "field1,fieldx" --out DBExport.csv
导出 json:
mongoexport -d DBName -c CollectionName --type=json --out DBExport.json

mongoimport

导入 CSV:
mongoimport -d DBName -c CollectionName --type=csv --headerline --file DBExport.csv
导入 json:
mongoimport -d DBName -c CollectionName --type=json --file DBExport.csv

发表评论