I make an app using node.js. and connect this with MongoDB. But when I start my server it gives me an error. The error is below.
Example app listening on port 5000
MongoServerError: bad auth : Authentication failed.
at Connection.onMessage (C:\Taha\Project\Assignment\11.warehouse\server\node_modules\mongodb\lib\cmap\connection.js:203:30)
at MessageStream.<anonymous> (C:\Taha\Project\Assignment\11.warehouse\server\node_modules\mongodb\lib\cmap\connection.js:63:60)
at MessageStream.emit (node:events:390:28)
at processIncomingData (C:\Taha\Project\Assignment\11.warehouse\server\node_modules\mongodb\lib\cmap\message_stream.js:108:16)
at MessageStream._write (C:\Taha\Project\Assignment\11.warehouse\server\node_modules\mongodb\lib\cmap\message_stream.js:28:9)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at MessageStream.Writable.write (node:internal/streams/writable:334:10)
at TLSSocket.ondata (node:internal/streams/readable:754:22)
at TLSSocket.emit (node:events:390:28)
at first, you need to import all necessary data and then set mongo credentials according to your
.env
files data instead of DB_USER and DB_PASS. make sure credentials data is the same as MongoDB provided. for ex:const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1, });