我正在尝试向本地MongoDB添加身份验证。
在我的配置中:
auth = true
setParameter = enableLocalhostAuthBypass=0
我使用:
执行mongod
服务器
/opt/local/bin/mongod --config /Users/gabriel/databases/mongo_data/conf/mongod.conf --setParameter enableLocalhostAuthBypass=0
并关注these instructions,使用local exception我尝试添加用户:
db.addUser({
user: "username",
pwd: "password",
roles: [ "userAdminAnyDatabase" ]
})
结果是n错误:
{
"user" : "username",
"pwd" : "aa5469a39788b6c3988537cd409887a1",
"roles" : [
"userAdminAnyDatabase"
],
"_id" : ObjectId("52a07b1ee11cb128a47b2a1b")
}
Thu Dec 5 14:09:50.373 couldn't add user: not authorized for insert on admin.system.users at src/mongo/shell/db.js:128
我做错了什么?
答案 0 :(得分:3)
设置enableLocalhostAuthBypass = 0
时,您明确禁止进行localhost身份验证。从配置中删除setParameter = enableLocalhostAuthBypass=0
并在没有mongod
的情况下启动--setParameter enableLocalhostAuthBypass=0
,所有内容都应按预期工作。