【发布时间】: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
【问题讨论】: