Mongodb无法使用addUser或createUser

时间:2016-12-21 12:21:40

标签: mongodb

我使用的是旧版本的mongo 2.2.3 我在64位服务器上安装它

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

sudo apt-get update

apt-get install mongodb-10gen=2.2.3

当我尝试创建用户

1.
     pt@ubuntu:~$ mongo
    MongoDB shell version v3.4.0
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 2.2.3
    WARNING: shell and server versions do not match

2

 > use admin
switched to db admin
> db.addUser("admin","password")
2016-12-21T17:46:09.712+0530 E QUERY    [main] TypeError: db.addUser is not a function :
@(shell):1:1




    db.createUser({user:"admin",pwd:"password",roles:["adminUser"]})
        2016-12-21T17:48:02.435+0530 E QUERY    [main] Error: 'createUser' command not found.  This is most likely because you are talking to an old (pre v2.6) MongoDB server :
        DB.prototype.createUser@src/mongo/shell/db.js:1281:1
        @(shell):1:1

在mongodocs中没有明确提及。

1 个答案:

答案 0 :(得分:2)

如果您还不知道控制台上的消息,那么您正在混合使用shell和服务器版本。 shell版本可能在某种程度上向后兼容,但服务器版本不是。所以看起来你的意图是使用2.2.3服务器。

https://docs.mongodb.com/v2.2/reference/method/db.addUser/

db.addUser("admin" , "pass" , true )

createUser是2.6服务器版本中的新命令。

另一方面,您应该尝试使用3.4服务器版本。

此处更多2.2版本https://docs.mongodb.com/v2.2/tutorial/control-access-to-mongodb-with-authentication/#add-users

相关问题