2016-03-07 126 views
0

我创建了一个名为学生数据库中的用户名和密码。MongoDB的壳身份验证错误

db.createUser({用户: '克特林',密码: '克特林',角色:[{作用: 'userAdmin',DB: '学生'}]});

所以我重新启动的MongoDB服务器与此命令:

mongod --auth --dbpath C:\data\db 
在另一终端

,我连接到与服务器:

mongo 

然后查询的服务器:

> db.getUsers() 
[ 
    { 
      "_id" : "student.Catalin", 
      "user" : "Catalin", 
      "db" : "student", 
      "roles" : [ 
        { 
          "role" : "userAdmin", 
          "db" : "student" 
        } 
      ] 
    } 

]

跑到学生数据库:

> use student 
switched to db student 

进入我的用户名和密码,通过这个命令成功地:

> db.auth('Catalin','Catalin'); 
1 

,当我想查看我的收藏我得到一个错误,为什么呢? :

> show collections 
2016-03-07T15:54:41.166+0300 E QUERY [thread1] Error: listCollections failed: 
{ 
    "ok" : 0, 
    **"errmsg" : "not authorized on student to execute command { listCollectio 
ns: 1.0, filter: {} }",** 
    "code" : 13 
} : 
[email protected]/mongo/shell/utils.js:23:13 
[email protected]/mongo/shell/db.js:746:1 
[email protected]/mongo/shell/db.js:758:15 
[email protected]/mongo/shell/db.js:769:12 
[email protected]/mongo/shell/utils.js:695:9 
[email protected]/mongo/shell/utils.js:594:15 
@(shellhelp2):1:1 

“errmsg”:“未经学生授权执行命令{listCollectio ns:1.0,filter:{}}“,

P.S. :我正在使用mongoDB 3.2

回答