MongoDB导入导出

编程知识 更新时间:2023-05-02 21:14:25

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

 

 

更多推荐

MongoDB导入导出

本文发布于:2023-04-28 17:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/3be7ce85e38bcd201e446cf1c49ce517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MongoDB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 109229文章数
  • 27722阅读数
  • 0评论数