Authentication problem on Atlas

Hello, Im new in this. I have authentication problem connecting to MongoDB Atlas collection with NodeJS.
What is wrong?

Error: MongoServerError: bad auth : authentication failed

Connection string:


Node code:

    .connect(process.env.mongodb_url, {
        useNewUrlParser: true,
        useUnifiedTopology: true
    .then(() => console.log("Mongodb Connected..."))
    .catch((err) => console.error(err));

Can you connect with Compass or mongosh?

If not, you have the wrong user name direktor or the wrong password password123! .

If I install Mongo on localhost works fine, just not online on Atlas.

It sounds like you may have a wrong password or username like steevej suggests.

That, or you’re connecting to the wrong port. I would doublecheck and verify the information, and if it is correct we can dig deeper into this.

I suspect it is due to special character “!” in your password
You have to escape it or use Uriencoder or call password separately instead of using it in connect string or change PWD to a simple one

This would work: mongodb_url=mongodb://

It works because you are connecting to local mongodb without access control enabled
Your requirement is to connect to Atlas with userid/PWD
Try to replicate the same in your local instance and see if you can connect(enable access control and create user and PWD with special character)