MongoDB Atlas, mongoose doesn't connect

Hey guys, I have the following problem,
I have tested the connection using Mongo Client in my project and I was able to connect my DB on MongoDB Atlas, but when I use mongoose it says was unable to connect.

Can you share your code?

var mongoose = require(“mongoose”);
const uri = process.env[‘MONGO_URI’];
mongoose.connect(uri, { useNewUrlParser: true, useFindAndModify: false,
useUnifiedTopology: true });




Your app is listening on port 3000
(node:112) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 4 to closed
at TLSSocket. (/home/runner/boilerplate-mongomongoose/node_modules/mongodb-core/lib/connection/connection.js:276:9)
at Object.onceWrapper (events.js:421:26)
at TLSSocket.emit (events.js:326:22)
at net.js:675:12
at TCP.done (_tls_wrap.js:568:7)
(node:112) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see Command-line options | Node.js v16.10.0 Documentation). (rejection id: 1)
(node:112) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This seems similar to:

Have you whitelisted your IP?

Yes, I have made my research for this problem before, but even so doesn’t work, I will check the other post. thank you for your time


Did you replace username with your actual username and password with the matching password? What about the name of the database and the cluster?

0:00 - Intro to MongoDB
2:24 - MongoDB setup in Atlas
6:51 - Mongoose
19:26 - Getting & saving data
30:33 - Outputting documents in views

Have you followed steps similar to that in this video?

I did it, worked! I need to change the “package,json”, and get the more recent version of MongoDB(^4.1.3), mongoose(^6.0.9), and Express(^4.17.1), and worked fine, thanks for the help, I really appreciate it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.