0

I have installed dotenv while creating the mongodb file. then i got my user and password. to secure that i used .env file like

"${process.env.DB_USER}:${process.env.DB_PASS}"

then it is showing me bad auth. along with that it is showing codeName:

'AtlasError',
  [Symbol(errorLabels)]: Set(1) { 'HandshakeError' } this. 
1
  • What's the console.log(`"${process.env.DB_USER}:${process.env.DB_PASS}"`) say? Commented May 20, 2022 at 9:49

1 Answer 1

2

I see you have used "" for the encapsulation and ${} (template literals):

"${process.env.DB_USER}:${process.env.DB_PASS}"

You have to use backticks like below to make this work and not double quotes:

`${process.env.DB_USER}:${process.env.DB_PASS}`

This one's a common problem that's been done by new folks working with JavaScript's new features.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. I am actually a newcomer!
Thanks! I didn't know that too. Now I have accepted your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.