- 导入导出数据命令:
mongoexport、mongoimport:导出导入表(-c)、或字段;
mongodump、mongorestore:导出导入(所有或单个)数据库(-d); - options: {
-d: 数据库名,
-c: 数据表名(collection),
-o: 导出的路径,或文件名(.dat),
--file: 导入文件,
--csv: 表明导出 csv 格式,默认是 json 格式
-h: 主机地址,
--port: 主机端口,
-u: 用户名,
-p: 密码,
--ssl: 以 SSL 方式连接,
--drop: (mongorestore)删除已存在的数据
}
*例如:
- 导出:
- 导出(备份)所有数据库:
mongodump -h 127.0.0.1 --port 8020 -o /ustack/mongo_data/ - 导出(备份)数据库(数据库名:ustack_interview_dev):
mongodump -d ustack_interview_dev -o /usatck/mongo_data/ - 导出数据表(collection)(数据库名:ustack_interview_dev;数据表名:questions):
mongoexport -d ustack_interview_dev -c questions -o /ustack/mongo_data/questions.dat - 导出 csv 格式数据表(collection)(数据库名:ustack_interview_dev;数据表名:questions):
mongoexport -d ustack_interview_dev -c questions --csv -o /ustack/mongo_data/questions.csv
- 导出(备份)所有数据库:
- 导入:
- 导入数据库:
mongorestore -h 127.0.0.1 --port 8020 /ustack/mongo_data/ - 导入数据表:
mongoimport -d ustack_interview_dev -c questions --file /ustack/mongo_data/ustack_interview_dev/questions.dat - 导入 csv 格式数据表:
mongoimport -d ustack_interview_dev -c questions --type csv --file /ustack/mongo_data/ustack_interview_dev/questions.csv
- 导入数据库: