Error message : MongoServerError: bad auth :Authentication failed

What is the reason behind this error? this code I am using to connect to DB.

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

1 answer

  • answered 2022-05-07 07:08 Aayush Shrestha

    Check if you have access to your env contents first, by adding this line console.log(process.env.DB_USER, process.env.DB_PASSWORD).

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum