how to fix: 'MongoError: authentication fail' @MongoDB Atlas
You have to put your user
and password
in your connection uri string
mongodb://***'your user':' here comes password '***@mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
e.g
mongodb://dbuser:dbpassword@mongo-cluster-shard-00-00-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-01-ixqtu.mongodb.net:27017,mongo-cluster-shard-00-02-ixqtu.mongodb.net:27017/test?ssl=true&replicaSet=mongo-cluster-shard-0&authSource=admin&retryWrites=true
The problem is I was leaving <> in connection string. You have to remove those for authentication to work.
I was facing this issue too. But after an hour I came to know that I used the process.env variables for username and password. And also declared them in the .env file. But I forgot to configure dotenv package in my code.
So make sure you didn't make this kind of silly mistake.
For more info go through this documentation of node repositories.https://www.npmjs.com/package/dotenv