Tell us what’s happening:
my issue is with connecting to my mongoDB database in myApp.js.
Your code so far
Below is the error message i see in my terminal:
Your app is listening on port 3000
(node:4589) [DEP0170] DeprecationWarning: The URL mongodb://mad-user:mad-user@ac-o2gmjhh-shard-00-00.woxxsds.mongodb.net:27017,ac-o2gmjhh-shard-00-01.woxxsds.mongodb.net:27017,ac-o2gmjhh-shard-00-02.woxxsds.mongodb.net:27017/mad-user?authSource=admin&replicaSet=atlas-xs4e3q-shard-0&retryWrites=true&w=majority&appName=Cluster0&ssl=true is invalid. Future versions of Node.js will throw an error.
(Use node --trace-deprecation ...
to show where the warning was created)
/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/connection.js:299
callback(new MongoError(document));
^
MongoError: bad auth : authentication failed
at MessageStream.messageHandler (/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/connection.js:299:20)
at MessageStream.emit (node:events:519:28)
at processIncomingData (/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (node:internal/streams/writable:564:12)
at _write (node:internal/streams/writable:493:10)
at Writable.write (node:internal/streams/writable:502:10)
at TLSSocket.ondata (node:internal/streams/readable:1007:22)
at TLSSocket.emit (node:events:519:28)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Readable.push (node:internal/streams/readable:390:5)
at TLSWrap.onStreamRead (node:internal/stream_base_commons:191:23) {
ok: 0,
code: 8000,
codeName: ‘AtlasError’
}
const mongoose = require(‘mongoose’);
require(‘dotenv’).config();
mongoose.connect(‘mongodb+srv://mad-user:mad-user@cluster0.woxxsds.mongodb.net/mad-user?retryWrites=true&w=majority&appName=Cluster0’, { useNewUrlParser: true, useUnifiedTopology: true })
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Basic Node and Express - Use the .env File