MongoServerError: bad auth : authentication failed code:8000

Hey,

I’m facing issue in production on render.com while connecting to db( i have added env variables correctly as i have added in local), in my local i used same credentials its working fine. can anyone help how to resolve this error

MongoServerError: bad auth : authentication failed
Nov 27 11:44:33 PM at Connection.onMessage (/opt/render/project/src/node_modules/mongodb/lib/cmap/connection.js:202:26)
Nov 27 11:44:33 PM at MessageStream. (/opt/render/project/src/node_modules/mongodb/lib/cmap/connection.js:61:60)
Nov 27 11:44:33 PM at MessageStream.emit (node:events:514:28)
Nov 27 11:44:33 PM at processIncomingData (/opt/render/project/src/node_modules/mongodb/lib/cmap/message_stream.js:124:16)
Nov 27 11:44:33 PM at MessageStream._write (/opt/render/project/src/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
Nov 27 11:44:33 PM at writeOrBuffer (node:internal/streams/writable:447:12)
Nov 27 11:44:33 PM at _write (node:internal/streams/writable:389:10)
Nov 27 11:44:33 PM at Writable.write (node:internal/streams/writable:393:10)
Nov 27 11:44:33 PM at TLSSocket.ondata (node:internal/streams/readable:817:22)
Nov 27 11:44:33 PM at TLSSocket.emit (node:events:514:28) {
Nov 27 11:44:33 PM ok: 0,
Nov 27 11:44:33 PM code: 8000,
Nov 27 11:44:33 PM codeName: ‘AtlasError’,
Nov 27 11:44:33 PM connectionGeneration: 0,
Nov 27 11:44:33 PM [Symbol(errorLabels)]: Set(2) { ‘HandshakeError’, ‘ResetPool’ }
Nov 27 11:44:33 PM }
Nov 27 11:44:35 PM Your service is live :tada:

This is indicative of an incorrect username or password in your connection string. You might want to double check that the environment variables you’ve supplied in render don’t contain any extra whitespace, or just inline the entire connection string as you copied it from the Atlas connection modal.

1 Like