Darron Tavares
Darron Tavares

Reputation: 1

Mongo: Bad Auth Authentication failed.

I am trying to do a mongoose connection from Mongo Atlas. I have a cluster ayman and I am trying to connect it from Terminal(Ubuntu 18). It says that I have successfully connected to the shard, but it says authentication failed. I am giving credentials defined as SCRAM on Mongo Atlas. 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

Cluster name: ayman

Username: aymanpatel

MongoDB shell version v3.6.3

Upvotes: 0

Views: 4596

Answers (1)

Mehdi.K
Mehdi.K

Reputation: 21

Try to do something like these:

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));

Upvotes: 1

Related Questions