我创建了一个replicaset rs0,我有:
mongo1.mydomain.com
mongo2.mydomain.com
mongo3.mydomain.com
这是我的rs.conf
rs0:PRIMARY> rs.conf()
{
"_id" : "rs0",
"version" : 3,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "mongo1.mydomain.com:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "mongo2.mydomain.com:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "mongo3.mydomain.com:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 60000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5a0ca4fe5e8a441fcd6aa77d")
}
}
目前mongo3是主要的(我关闭了mongo1,这是主要的,然后重新启动它)
然后我有一个DB myDB,其中创建了一个用户(带有破折号)(具有读写权限):
rs0:PRIMARY> use myDB
switched to db myDB
rs0:PRIMARY> db.auth("my-server-user", "Test1234");
1
rs0:PRIMARY>
我现在尝试使用URI连接到我的replicaset(所有端口暂时打开我的服务器),但是我收到错误:
MongoDB server version: 3.4.10
2017-11-15T22:13:01.241+0100 E QUERY [thread1] Error: Authentication failed.
DB.prototype._authOrThrow@src/mongo/shell/db.js:1461:20
@(auth):6:1
@(auth):1:2
exception: login failed
连接我使用:
mongo "mongodb://mongo1.mydomain.com:27017,mongo2.mydomain.com:27017,mongo3.mydomain.com:27017/myDB?replicaSet=rs0" --authenticationDatabase admin --username my-server-user --password Test1234
你有什么想法吗?
提前致谢
答案 0 :(得分:0)
通过删除找到了确定:
--authenticationDatabase admin
我明白了:
mongo "mongodb://mongo1.mydomain.com:27017,mongo2.mydomain.com:27017,mongo3.mydomain.com:27017/myDB?replicaSet=rs0" --username my-server-user --password Test1234