我正在尝试从 Mongo Atlas 建立猫鼬连接。我有一个群集ayman
,我正在尝试从Terminal(Ubuntu 18)连接它。
它表示我已成功连接到分片,但表示身份验证失败。我提供了在Mongo Atlas上定义为SCRAM的凭据。 Mongo Security Page
mongo "mongodb://ayman-shard-00-00-xxzs1.mongodb.net:27017,ayman-shard-00-01-xxzs1.mongodb.net:27017,ayman-shard-00-02-xxzs1.mongodb.net:27017/test?replicaSet=ayman-shard-0" --ssl --authenticationDatabase admin --username aymanpatel --password <PASSWORD>
MongoDB shell version v3.6.3
connecting to: mongodb://ayman-shard-00-00-xxzs1.mongodb.net:27017,ayman-shard-00-01-xxzs1.mongodb.net:27017,ayman-shard-00-02-xxzs1.mongodb.net:27017/test?replicaSet=ayman-shard-0
2018-10-07T09:40:34.288+0530 I NETWORK [thread1] Starting new replica set monitor for ayman-shard-0/ayman-shard-00-00-xxzs1.mongodb.net:27017,ayman-shard-00-01-xxzs1.mongodb.net:27017,ayman-shard-00-02-xxzs1.mongodb.net:27017
2018-10-07T09:40:34.336+0530 I NETWORK [thread1] Successfully connected to ayman-shard-00-01-xxzs1.mongodb.net:27017 (1 connections now open to ayman-shard-00-01-xxzs1.mongodb.net:27017 with a 5 second timeout)
2018-10-07T09:40:34.339+0530 I NETWORK [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to ayman-shard-00-02-xxzs1.mongodb.net:27017 (1 connections now open to ayman-shard-00-02-xxzs1.mongodb.net:27017 with a 5 second timeout)
2018-10-07T09:40:34.393+0530 I NETWORK [thread1] Successfully connected to ayman-shard-00-00-xxzs1.mongodb.net:27017 (1 connections now open to ayman-shard-00-00-xxzs1.mongodb.net:27017 with a 5 second timeout)
MongoDB server version: 3.6.8
2018-10-07T09:40:34.517+0530 I NETWORK [thread1] Marking host ayman-shard-00-00-xxzs1.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node ayman-shard-00-00-xxzs1.mongodb.net:27017: bad auth Authentication failed.
2018-10-07T09:40:34.562+0530 I NETWORK [thread1] Successfully connected to ayman-shard-00-01-xxzs1.mongodb.net:27017 (1 connections now open to ayman-shard-00-01-xxzs1.mongodb.net:27017 with a 0 second timeout)
2018-10-07T09:40:34.609+0530 I NETWORK [thread1] Marking host ayman-shard-00-01-xxzs1.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node ayman-shard-00-01-xxzs1.mongodb.net:27017: bad auth Authentication failed.
2018-10-07T09:40:34.655+0530 I NETWORK [thread1] Successfully connected to ayman-shard-00-02-xxzs1.mongodb.net:27017 (1 connections now open to ayman-shard-00-02-xxzs1.mongodb.net:27017 with a 0 second timeout)
2018-10-07T09:40:34.705+0530 I NETWORK [thread1] Marking host ayman-shard-00-02-xxzs1.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node ayman-shard-00-02-xxzs1.mongodb.net:27017: bad auth Authentication failed.
2018-10-07T09:40:34.731+0530 I NETWORK [thread1] Marking host ayman-shard-00-00-xxzs1.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node ayman-shard-00-00-xxzs1.mongodb.net:27017: bad auth Authentication failed.
2018-10-07T09:40:34.731+0530 E QUERY [thread1] Error: can't authenticate against replica set node ayman-shard-00-00-xxzs1.mongodb.net:27017: bad auth Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20
@(auth):6:1
@(auth):1:2
exception: login failed
集群名称:ayman
用户名:aymanpatel
MongoDB Shell版本v3.6.3
答案 0 :(得分:0)
尝试执行以下操作:
var mongoDB = 'mongodb+srv://aymanpatel:<password>@cluster0-lnhl4.mongodb.net/test?
retryWrites=true&w=majority';
mongoose.connect(mongoDB, { useNewUrlParser: true })
.then(() => console.log("MongoDb connected"))
.catch(err => console.log(err));