美文网首页
MongoDB 新建数据库后创建新数据库的用户时报错:not a

MongoDB 新建数据库后创建新数据库的用户时报错:not a

作者: 小虎虎你吼啊 | 来源:发表于2018-09-28 16:09 被阅读0次

在MongoDB开启验证的情况下,新建一个数据库 dbName

use dbName

之后为数据库 dbName 创建用户 dbUser

db.createUser({user:"dbUser",pwd:"blahblah",roles:[{role:"dbOwner",db:"dbName"}]})

无法创建,会报如下错误信息

couldn't add user: not authorized on dbName to execute command ...

解决方法

  • 关闭验证
    mongod.conf配置文件中的authorization置为disabled
  • 重启MongoDB
    /etc/init.d/mongod restart
  • 进入mongo控制台执行之前创建用户的命令
  • 开启验证
    mongod.conf配置文件中的authorization置为enabled

结束

相关文章

网友评论

      本文标题:MongoDB 新建数据库后创建新数据库的用户时报错:not a

      本文链接:https://www.haomeiwen.com/subject/gpjpoftx.html