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

Not Working: Throwing error with "localhost:27017" #12741

Merged
merged 2 commits into from Dec 16, 2022

Conversation

SadiqOnGithub
Copy link
Contributor

@SadiqOnGithub SadiqOnGithub commented Nov 30, 2022

by using mongoose.connect('mongodb://localhost:27017/test') by node application, running on windows, is throwing this error :

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
    at Connection.openUri (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\connection.js:824:32)
    at C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\index.js:412:10
    at C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
    at new Promise (<anonymous>)
    at promiseOrCallback (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
    at Mongoose._promiseOrCallback (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\index.js:1265:10)    
    at Mongoose.connect (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\index.js:411:20)
    at main (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\server.js:6:17)
    at Object.<anonymous> (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\server.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1205:14) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) { 'localhost:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
}

==================================X==================================

I apologize if this proposed change is not up to the mark or is violating some community guidelines.

but I wasted a lot of time on this so I can't resist but propose this change.

I think other people also have struggled with this
read more on this stack overflow answer : https://stackoverflow.com/a/70517348/14075519

Summary

Examples

by using -- mongoose.connect('mongodb://localhost:27017/test')  --  by node application, running on windows, is throwing this error : 

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
    at Connection.openUri (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\connection.js:824:32)
    at C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\index.js:412:10
    at C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\helpers\promiseOrCallback.js:41:5
    at new Promise (<anonymous>)
    at promiseOrCallback (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\helpers\promiseOrCallback.js:40:10)
    at Mongoose._promiseOrCallback (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\index.js:1265:10)    
    at Mongoose.connect (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\node_modules\mongoose\lib\index.js:411:20)
    at main (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\server.js:6:17)
    at Object.<anonymous> (C:\Users\lenovo\Documents\webistes projects\Node\node prac\mongo\server.js:3:1)
    at Module._compile (node:internal/modules/cjs/loader:1205:14) {
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) { 'localhost:27017' => [ServerDescription] },
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    setName: null,
    maxElectionId: null,
    maxSetVersion: null,
    commonWireVersion: 0,
    logicalSessionTimeoutMinutes: null
  },
  code: undefined
}


==================================X==================================

I apologize if this proposed change is not up to the mark or is violating some community guidelines.

but I wasted a lot of time on this so I can resist but propose this change.

I think other people also have struggled with this
read more on this stack overflow answer  :   https://stackoverflow.com/a/70517348/14075519
@hasezoey
Copy link
Collaborator

hasezoey commented Dec 2, 2022

This looks like it became a problem since NodeJS switched that localhost points to a IPv6 address instead of a IPv4 address in NodeJS 17.

And also looks like either mongodb or windows do not listen on the IPv6 address and only on the IPv4 address

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍 I've started using 127.0.0.1 for local dev since Node switched to using ipv6 by default, so this is a reasonable change.

@vkarpov15 vkarpov15 merged commit dfd5eeb into Automattic:master Dec 16, 2022
@vkarpov15 vkarpov15 added this to the 6.8.1 milestone Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants