个人博客
专注IT梦想的地方

MongoDB数据库添加管理员账户出现Property ‘addUser’ of object admin is not a function错误的解决方法

MongoDB数据库安装好后,我需要先添加管理员账户,然后再添加其他用户,但是通过安装进来,并且打开连接都有问题,就是在进入到admin权限下无法添加管理员账户,我执行的命令是:

> use admin
switched to db admin
> db.addUser({user:'test', pwd:'test', roles:['userAdminAnyDatabase'])
2015-11-15T04:37:02.159+0800 E QUERY TypeError: Property 'addUser' of object
admin is not a function at (shell):1:4

真是蛋疼…

最后在官方文档中发现,原来mongodb最新的版本中已经废弃了addUser这个方法,改用了createUser这个方法,我去,而且在更早的时候还直接使用过db.createUser(”username”, “password”)这样的方式,所以如果大家有遇到这样的情况,请自行更新到最新版本的createUser方法,并且传递相应的正确参数userAdminAnyDatabase,表示所有权限的意思。下面是最新的指令,已经成功执行。

> use admin
switched to db admin
> db.createUser({user:'test', pwd:'test123', roles:['userAdminAnyDatabase']})
Successfully added user: { "user" : "test", "roles" : [ "userAdminAnyDatabase" ] }
>

所以说mongodb就是个坑啊….

赞(160) 打赏
未经允许,不得转载本站任何文章:智言个人博客 » MongoDB数据库添加管理员账户出现Property ‘addUser’ of object admin is not a function错误的解决方法

评论 7

评论前必须登录!

 

  1. I have read so many articles or reviews regarding the blogger lovers
    but this piece of writing is truly a good paragraph, keep
    it up.

  2. I just like the valuable info you supply for your articles.
    I will bookmark your weblog and check once more here frequently.
    I’m moderately certain I’ll be informed lots of new stuff right right here!

    Good luck for the following!

  3. 不错哦,赞一个,求认识,求回访

    奇虎分享网8年前 (2016-08-23)
  4. 好吧, 关于这些真心不知道,不过还是顶一下

    漫道9年前 (2015-11-26)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏