- Mongoexport export JSON or CSV format
- Mongoimport Import JSON or CSV
- Mongodump Export binary Bson structure data and index information
- Mongorestore Importing binary files
Mongoexport
-h 主机--port 端口号-u 用户名-p 密码-d 库名-c 表名-f field1,field..... 导出的字段-q 查询条件 -o 导出文件名--csv 等同于 --type=csv 导出csv格式,一定要指定-f 导出字段才能导出csv
Example: Export the my_id<200 _id and username in the My table in the test database to CSV format
mongoexport -u test -p 64823723zk -d test -c my -q {my_id:{‘$lt‘:200}} --type=csv -f _id,username,a -o my.csv
Mongoimport
-d 导入的数据库-c 导入的表--type csv/json--file 文件路径
Example: Importing data from a Stu.json into a Stu table in the test database
mongoimport -u test -p 123 -d test -c stu --type json --file ./stu.json
Mongodump
-d 库名-c 表名-o 导出路径-f field1,field..... 字段名
Example: Export the My table of the test database with binary Bson structure data and index information to the dump directory
./mongodump-u test-p 123-d test-c my-o./dump
Mongorestore
-d 数据库--dir= bson跟索引信息存放的目录
Example:
mongorestore -u test -p 123 -d test --dir=./dump/test/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MongoDB Learning Note 07--Data backup, recovery