1.备份
mongodump -h localhost:27017 -d test -o E:\mongoDB\backup
localhost:27017 :MongoDB所在服务器地址,这里使用的是本地服务器
test 要备份的数据库名称
E:\MongoDB\backup :备份的数据库地址
执行命令后
相应文件
这样数据就备份完成了
2.数据恢复
先使用db.dropDatabase()
删除数据库以检测恢复
mongorestore -h localhost:27017 -d test E:\MongoDB\backup\test
localhost:27017 :MongoDB所在服务器地址,这里使用的是本地服务器
test 要恢复的数据库名称
E:\MongoDB\backup\test:数据库备份文件地址
执行命令后
这时候show collections
就会再次显示已经删除的集合了