From 8d9baf7ed75294b2cad90ea56f245bfbceeec3de Mon Sep 17 00:00:00 2001 From: Syed Sadiq Ali <69423208+SadiqOnGithub@users.noreply.github.com> Date: Wed, 30 Nov 2022 21:03:36 +0530 Subject: [PATCH 1/2] Not Working: Throwing error with "localhost:27017" 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 () 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. (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 --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 6d3a4da0b0e..505ab69f376 100644 --- a/docs/index.md +++ b/docs/index.md @@ -32,7 +32,7 @@ const mongoose = require('mongoose'); main().catch(err => console.log(err)); async function main() { - await mongoose.connect('mongodb://localhost:27017/test'); + await mongoose.connect('mongodb://127.0.0.1:27017/test'); // use `await mongoose.connect('mongodb://user:password@localhost:27017/test');` if your database has auth enabled } From 32ee09a57510a44e1428342620c621ea1ad37122 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 16 Dec 2022 15:00:24 -0500 Subject: [PATCH 2/2] Update index.md --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 505ab69f376..c791af2cddc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -34,7 +34,7 @@ main().catch(err => console.log(err)); async function main() { await mongoose.connect('mongodb://127.0.0.1:27017/test'); - // use `await mongoose.connect('mongodb://user:password@localhost:27017/test');` if your database has auth enabled + // use `await mongoose.connect('mongodb://user:password@127.0.0.1:27017/test');` if your database has auth enabled } ```