1

Error to connect the DB : MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at _handleConnectionErrors (C:\MERN_INTERN\Demo Project\backend\node_modules\mongoose\lib\connection.js:755:11) at NativeConnection.openUri (C:\MERN_INTERN\Demo Project\backend\node_modules\mongoose\lib\connection.js:730:11)

i try to connect the mongoDB compass with node.js

  • Basically main problem is with mongoDB server could not connect with IPV6 – Sohaib ahmad Mar 13 '23 at 03:12
  • Does this answer your question? [Can't connect to MongoDB 6.0 Server locally using Nodejs driver](https://stackoverflow.com/questions/74609210/cant-connect-to-mongodb-6-0-server-locally-using-nodejs-driver) – Wernfried Domscheit Mar 13 '23 at 07:12
  • the mods would rather have answers deleted and make the people looking for answers wander around 100s of links than let them see the answer on whichever they found. No wonder newbies don't ask on SO anymore. They really hate newbies getting the solutions to their problems. – PrathamJ Aug 04 '23 at 08:49

1 Answers1

0

There are two solutions I found by searching on Google to resolve this issue.

The main problem is with the MongoDB server not being able to connect with IPV6.

To resolve this issue you can do one of thee options:

Option 1:

mongoose.connect('mongodb://127.0.0.1/test');

Option 2:

const connect = await mongoose.connect(process.env.CONNECTION_STRING, {
            useNewUrlParser: true, 
            useUnifiedTopology: true,
            family: 4,
        });
Aymendps
  • 1,346
  • 4
  • 20