'MongoError: bad auth Authentication failed

const uri=`mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASS}@cluster0.crceb.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`;

When I run the code I am getting the following error

"MongoError: bad auth Authentication failed."

Any ideas that's mean?



Solution 1:[1]

Check the env file correctly. And add project name too. If not, then change the password so that if it includes a number, write just a letter. You can try another world inside of DB_USER

check your env data in console.log and consider it with your env file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ümit Arslan