I’m using the following connection string:
mongodb+srv://<username>:<password>@sampleCluster.closbxy.mongodb.net/?retryWrites=true&w=majority
with the code
mongoose.connect(process.env.MONGO_URI).then(() => {
console.log('Connected to database!')
}).catch(err => {
console.log(err)
})
to connect to the mongoDB, but it is unable to connect. Could anyone please advise what to do here?
Learn to Code — For Free
Hello and welcome to the forum!
Did you follow the tutorial linked in the challenge description?
For the following challenges, you are going to use MongoDB to store data. To simplify the configuration, you'll use a service called MongoDB Atlas. Create a MongoDB Atlas Account MongoDB Atlas is a MongoDB Database-as-a-Service platform, which means...
You have saved your connection string in your .env
file (or in your Secrets tab if you’re on Replit)? You have also inserted your username and password into your URI?
Also, as per the challenge instructions, your MongoDB connection should include the following:
mongoose.connect(<Your URI>, { useNewUrlParser: true, useUnifiedTopology: true });
…otherwise your URI will not be correctly parsed.
Do you have a link to your repl or project code please?
I have also edited your post to include a direct link to the challenge. It’s much easier to help you if you include that also.
system
Closed
November 30, 2023, 11:32pm
3
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.