备份
不需要进入mongo,直接在命令行输入
mongodump -h 127.0.0.1:27017 -u xxxx -p xxxx --authenticationDatabase admin -d 数据库名字 -o 导出路径
如果不加 - -authenticationDatabase admin认证,可能会报错
Err: command listCollections requires authentication
还原
mongorestore -h 127.0.0.1:27017 -u xxxx -p xxxx --authenticationDatabase admin -d 数据库名字 -o 导出数据路径
mongo好像在4.4版本之后没有mongorestore命令了,需要去官网额外下载安装配置https://www.mongodb.com/try/download/database-tools