MongoDB导入导出

1、单库导出

./mongodump -h ip:port -u username -p password -d databasename -o pathToSave
示例

./mongodump -h 127.0.0.1:27017 -u uname -p pwd -d my_demo -o ../databak/

2、单库还原

./mongorestore -h ip:port  -u uname -p pwd -d  databasename path/my_demo [--drop]

./mongorestore -h ip:port  [--authenticationDatabase admin -u admin -p adminpwd] -d  databasename path/my_demo [--drop]

错误示例

./mongorestore -h 127.0.0.1:27017 -d my_demo ../databak/my_demo (×错误)

报错信息:the the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead

正确示例

  • 不删除原有数据的还原
./mongorestore -h 127.0.0.1:27017 -u uname -p pwd -d my_demo ../databak/my_demo (√正确)

  • 删除原有数据的还原,加 --drop
./mongorestore -h 127.0.0.1:27017 -u uname -p pwd -d my_demo ../databak/my_demo --drop (√正确)

  • 如果还原的时候报权限问题,需要加上管理员的账号密码 --authenticationDatabase admin -u admin -p adminpwd

auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.

./mongorestore -h 127.0.0.1:27017 --authenticationDatabase admin -u admin -p adminpwd -d my_demo ../databak/my_demo --drop

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值