MongoDB导入数据报错:Failed: restore error: ant.files: error reading database: not authorized on xxx

最近在导入MongoDB数据时遇到一个错误:	
[root@]# mongorestore --host 127.0.0.1 --port 27017 --username xxx --password  xxx  --authenticationDatabase admin  --db xxx  --dir xxxx
2024-04-21T19:56:21.615+0800	building a list of collections to restore from xxx dir
2024-04-21T19:56:21.616+0800	Failed: restore error: ant.files: error reading database: not authorized on xxxx to execute command { listCollections: 1, cursor: { batchSize: 0 } }

出现这种情况是因为,admin库的用户没有足够权限恢复数据到指定库,可以给用户增加MongoDB内置角色restore。
MongoDB备份和恢复角色:

admin数据库包含下列角色用来备份和恢复数据
backup:提供最小的备份数据的权限,该角色提供了足够的权限用于:MongoDB cloud manager 备份代理、ops manager 备份代理或者用于mongodump备份整个mongod实例
restore:提供权限用来从备份恢复数据,但是不包括system.profile集合数据。此角色提供了足够的权限用于使用不带–oplogReplay选项的mongorestore恢复数据
使用下面代码更新用户角色:

db.updateUser( "MyUserAdmin",
  { roles : [  
    { role : "restore", db : "admin"  },
    { role : "backup", db : "admin"  }
  ] } )

更新完成后即可正常恢复数据到指定库。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值