javascript - MongooseServerSelectionError: read ECONNRESET - Stack Overflow

I'm trying to connect my Nodejs application to MongoDB Atlas but it's throwing an error. Here

I'm trying to connect my Nodejs application to MongoDB Atlas but it's throwing an error.

Here is the error message:

This is the error in the catch block: MongooseServerSelectionError: read ECONNRESET DB connection error: read ECONNRESET

Below is the code for my Nodejs application:

const mongoose = require("mongoose");
const dotenv = require("dotenv");
dotenv.config();

//db connection
mongoose
  .connect(process.env.MONGO_URI, {
    useNewUrlParser: true,
    useUnifiedTopology: true
  })
  .then(() => console.log("DB Connected"))
  .catch(err => {
    console.log("This is the error in the catch block: " + err);
  });

mongoose.connection.on("error", err => {
  console.log(`DB connection error: ${err.message}`);
});

NOTE:- I declared .env file in which I have a variable MONGO_URI to hold the secret key required for connecting to MongoDB Atlas.

I'm trying to connect my Nodejs application to MongoDB Atlas but it's throwing an error.

Here is the error message:

This is the error in the catch block: MongooseServerSelectionError: read ECONNRESET DB connection error: read ECONNRESET

Below is the code for my Nodejs application:

const mongoose = require("mongoose");
const dotenv = require("dotenv");
dotenv.config();

//db connection
mongoose
  .connect(process.env.MONGO_URI, {
    useNewUrlParser: true,
    useUnifiedTopology: true
  })
  .then(() => console.log("DB Connected"))
  .catch(err => {
    console.log("This is the error in the catch block: " + err);
  });

mongoose.connection.on("error", err => {
  console.log(`DB connection error: ${err.message}`);
});

NOTE:- I declared .env file in which I have a variable MONGO_URI to hold the secret key required for connecting to MongoDB Atlas.

Share Improve this question edited Mar 3, 2020 at 5:02 AnonSar asked Mar 3, 2020 at 3:58 AnonSarAnonSar 7062 gold badges9 silver badges27 bronze badges 2
  • Did you whitelist your IP address on Atlas? – Tunmise Ogunniyi Commented Mar 3, 2020 at 13:29
  • Atlas requires SSL by default, does your connection string call for that? – Joe Commented Mar 3, 2020 at 22:24
Add a ment  | 

1 Answer 1

Reset to default 7

I was connected to a Wi-Fi connection that was having some policies due to which it was placing some restrictions and thus I was getting the above error.

I connected to another Wi-Fi connection ( not having any policies or restrictions ) and that fixed my problem.

Cheers!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744309460a4567879.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信