Kir*_*n G 1 permissions admin mongodb
我新安装了MongoDB 3.2并尝试创建第一个抛出以下错误的用户.
"错误:无法添加用户:管理员未授权执行命令"
我按照mongoDB 3.2文档,https: //docs.mongodb.org/manual/tutorial/enable-authentication/
要添加管理员,我尝试了以下代码,导致上述错误
创建用户管理员.添加具有userAdminAnyDatabase角色的用户.例如,以下内容在admin数据库上创建用户myUserAdmin:
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "MY_PASSWORD",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
Run Code Online (Sandbox Code Playgroud)
我经历了其他stackoverflow的答案,但没有运气,
我的完整错误,
E QUERY [thread1] Error: couldn't add user: not authorized on admin to execute command { createUser: "myUserAdmin
", pwd: "xxx", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 30000.0
} } :
_getErrorWithCode@src/mongo/shell/utils.js:23:13
DB.prototype.createUser@src/mongo/shell/db.js:1225:11
@(shell):1:1
Run Code Online (Sandbox Code Playgroud)
谢谢
如果您重新使用现有数据库目录 /data/db,则可能以前已经设置了用户/身份验证.
你可以:
然后运行mongod没有--auth
use admin;
db.getUsers(); // to see whether there's already an existing user.
Run Code Online (Sandbox Code Playgroud)
使用db.removeUser()删除现有用户.
| 归档时间: |
|
| 查看次数: |
6304 次 |
| 最近记录: |