首先我以管理员身份登录我的mongodb:
sudo mongo admin --username root --password XXXXXXXX
然后我创建了另一个具有root角色的用户:
> use admin
> db.createUser(
{
user: "myuser",
pwd: "myPassw",
roles: [ "root" ]
}
)
然后我写道:
> db.getUsers()
我的用户在那里:
{
"_id" : "admin.root",
"user" : "root",
"db" : "admin",
"roles" : [
{
"role" : "readWriteAnyDatabase",
"db" : "admin"
},
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "dbAdminAnyDatabase",
"db" : "admin"
},
{
"role" : "clusterAdmin",
"db" : "admin"
}
]
},
{
"_id" : "admin.myuser",
"user" : "myuser",
"db" : "admin",
"roles" : [
{
"role" : "root",
"db" : "admin"
}
]
}
现在,当我尝试登录时:
sudo mongo admin --username myuser --password myPassw
MongoDB shell version: 3.2.1
connecting to: /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017/admin
2016-02-10T21:23:53.964+0000 E QUERY [thread1] Error: Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1395:16
@(auth):6:1
@(auth):1:2
exception: login failed
这是什么原因?我重新启动了mongodb进程,但没有帮助。
=======编辑:
按照罗比的建议后,我在没有sudo
的情况下运行命令,不幸的是结果是:
bitnami@ip-172-31-47-102:~/stack$ mongo admin -u myuser -p myPassw
MongoDB shell version: 3.2.1
connecting to: /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017/admin
2016-02-10T21:56:15.615+0000 W NETWORK [thread1] Failed to connect to /opt/bitnami/mongodb/tmp/mongodb-27017.sock:0, reason: errno:13 Permission denied
2016-02-10T21:56:15.615+0000 E QUERY [thread1] Error: couldn't connect to server /opt/bitnami/mongodb/tmp/mongodb-27017.sock:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6
exception: connect failed
答案 0 :(得分:3)
我找到了解决方案,
密码中的符号是问题,因为我有$符号,更改密码没有符号为我工作!!