【问题标题】:MongoDB shell authentication errorMongoDB shell 身份验证错误
【发布时间】:2016-06-21 01:32:30
【问题描述】:

我为一个名为student的数据库创建了一个用户名和密码。:

db.createUser({user:'Catalin',pwd:'Catalin',roles:[{role:'userAdmin',db:'student'}]});

所以我用这个命令重新启动了 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
} :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
DB.prototype._getCollectionInfosCommand@src/mongo/shell/db.js:746:1
DB.prototype.getCollectionInfos@src/mongo/shell/db.js:758:15
DB.prototype.getCollectionNames@src/mongo/shell/db.js:769:12
shellHelper.show@src/mongo/shell/utils.js:695:9
shellHelper@src/mongo/shell/utils.js:594:15
@(shellhelp2):1:1

"errmsg" : "未授权学生执行命令 { listCollectio ns:1.0,过滤器:{} }",

附: :我正在使用 mongoDB 3.2

【问题讨论】:

    标签: mongodb database


    【解决方案1】:

    userAdmin 内置角色仅提供在数据库上创建和修改角色和用户的能力。如果您需要访问数据库,则需要分配 database roles 或其他具有数据库访问权限的角色,例如 dbOwner

    请参阅Built-in Roles 了解更多详细信息。

    您可能还会发现这些有用:

    【讨论】:

      猜你喜欢
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多