我新安装了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)
谢谢