MongoServerError: bad auth: Auth failed in other pc

Hi there, Im was working on my PC with no problems, everything works. I want to work in my project on my laptop and copied the entire project folder. When I want to start (npm run dev) the console gave me this error. I dont know what to do, if anyone could help I will be greatful.

[nodemon] restarting due to changes...
[nodemon] starting node server.js
Servidor escuchando en el puerto: 3001
ERROR en la conexión con la base de datos MongoServerError: bad auth : Authentication failed.
    at Connection.onMessage (/Users/carlos/Downloads/atlantico-proyecto/node_modules/mongodb/lib/cmap/connection.js:202:26)
    at MessageStream.<anonymous> (/Users/carlos/Downloads/atlantico-proyecto/node_modules/mongodb/lib/cmap/connection.js:61:60)
    at MessageStream.emit (node:events:511:28)
    at processIncomingData (/Users/carlos/Downloads/atlantico-proyecto/node_modules/mongodb/lib/cmap/message_stream.js:124:16)
    at MessageStream._write (/Users/carlos/Downloads/atlantico-proyecto/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
    at writeOrBuffer (node:internal/streams/writable:399:12)
    at _write (node:internal/streams/writable:340:10)
    at Writable.write (node:internal/streams/writable:344:10)
    at TLSSocket.ondata (node:internal/streams/readable:774:22)
    at TLSSocket.emit (node:events:511:28) {
  ok: 0,
  code: 8000,
  codeName: 'AtlasError',
  connectionGeneration: 0,
  [Symbol(errorLabels)]: Set(2) { 'HandshakeError', 'ResetPool' }
1 Like

Hello @Carlos_Castellano_Herrera ,

Welcome to The MongoDB Community Forums! :wave:

I saw that you have not had a response to this topic yet, were you able to find a solution?

An authentication error typically indicates an incorrect password. If your password contains special characters, try wrapping them in quotes, or using URL encoding for special characters.

You may also want to verify that you are using your MongoDB user password. Note that this may be different to the password you use for your Atlas login. You can see your MongoDB Users by clicking the Security tab on your MongoDB Atlas cluster.


1 Like

I’m getting the same errors. On my PC, I have no errors with authentication using the same username, password, and database name. On my Mac, I keep getting authentication errors using the same .env file as on my PC.

1 Like

Hello ! For my part, i get the same error. Resolved instaling dotenv on the second computer :
npm install dotenv --save
hope it can help you !

1 Like