Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while connecting to localhost #11066

Closed
zivlakmilos opened this issue Dec 10, 2021 · 1 comment
Closed

Error while connecting to localhost #11066

zivlakmilos opened this issue Dec 10, 2021 · 1 comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@zivlakmilos
Copy link

zivlakmilos commented Dec 10, 2021

After I update my operating system and MongoDB I am started to get error while trying to connect to local MongoDB server.

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 at NativeConnection.Connection.openUri (.../node_modules/mongoose/lib/connection.js:797:32) at .../node_modules/mongoose/lib/index.js:332:10 at .../node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5 at new Promise (<anonymous>) at promiseOrCallback (.../node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10) at Mongoose._promiseOrCallback (.../node_modules/mongoose/lib/index.js:1158:10) at Mongoose.connect (.../node_modules/mongoose/lib/index.js:331:20) at Object.<anonymous> (.../app.js:45:10) at Module._compile (node:internal/modules/cjs/loader:1097:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10) { reason: TopologyDescription { type: 'Unknown', servers: Map(1) { 'localhost:27017' => [ServerDescription] }, stale: false, compatible: true, heartbeatFrequencyMS: 10000, localThresholdMS: 15, logicalSessionTimeoutMinutes: undefined } }

This is URL that I am using to connect to db: mongodb://localhost:27017/dbname

Also, when I try same URL in MongoDB Compass, everything works without problem.

I found out that when I change localhost to 17.0.0.1 it works perfect. I am note sure what causing this, but localhost should be same as 127.0.0.1. I tough fist that is problem with MongoDB server listening, but if that's case, it wouldn't be working from Compass too.

Versions:

  • Node: v17.1.0
  • MongoDB: 5.0.4
  • Mongoose: 6.1.0
@vkarpov15
Copy link
Collaborator

Start your MongoDB server with ipv6 support, or take a look at your /etc/hosts file and look for a line that looks like ::1 localhost. Make sure that ::1 localhost is after 127.0.0.1 localhost. The ::1:27017 part of your stack trace makes it look like localhost is getting resolved to an ipv6 address.

@vkarpov15 vkarpov15 added the help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary label Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

2 participants