MongoDB and Mongoose - Install and Set Up Mongoose

Tell us what’s happening:

I have followed the steps to create a hosted database and I’m fairly certain that my code is correct, but I keep running into this error:

Error: Invalid schema, expected mongodb or mongodb+srv
at module.exports (/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/url_parser.js:24:21)
at deprecated (node:internal/util:165:12)
at connect (/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/operations/connect.js:283:3)
at /workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/mongo_client.js:284:5
at maybePromise (/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/utils.js:692:3)
at MongoClient.connect (/workspace/boilerplate-mongomongoose/node_modules/mongodb/lib/mongo_client.js:280:10)
at /workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:836:12
at new Promise ()
at Connection.openUri (/workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/connection.js:832:19)
at /workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:351:10
at /workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise ()
at promiseOrCallback (/workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:1149:10)
at Mongoose.connect (/workspace/boilerplate-mongomongoose/node_modules/mongoose/lib/index.js:350:20)
at Object. (/workspace/boilerplate-mongomongoose/myApp.js:3:10)

Your code so far

myApp.js code:

require(‘dotenv’).config();
const mongoose = require(‘mongoose’);
mongoose.connect(process.env.MONGO_URI);

.env code:
MONGO_URI=‘mongodb+srv://amoagh_gopinath:brxWpll15lMrm1To@cluster0.9kup2cs.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0’;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36

Challenge Information:

MongoDB and Mongoose - Install and Set Up Mongoose

Remove the semicolon at the end of the string in the .env file.

Oh. I was struggling to find out what I was doing wrong. Thank you!

It is an easy mistake to make, but hard to debug based on the error message.

Error: Invalid schema, expected mongodb or mongodb+srv

The semicolon at the end isn’t really the first place you would look for the issue based on that error message.