Vaibhav Haldia
Vaibhav Haldia

Reputation: 51

MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017. I have tried all solutions given in the StackOverflow, but its not working

MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at NativeConnection.Connection.openUri (/mnt/d/Ecommerce/node_modules/mongoose/lib/connection.js:802:32)
    at /mnt/d/Ecommerce/node_modules/mongoose/lib/index.js:341:10        
    at /mnt/d/Ecommerce/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
    at new Promise (<anonymous>)
    at promiseOrCallback (/mnt/d/Ecommerce/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
    at Mongoose._promiseOrCallback (/mnt/d/Ecommerce/node_modules/mongoose/lib/index.js:1141:10)
    at Mongoose.connect (/mnt/d/Ecommerce/node_modules/mongoose/lib/index.js:340:20)
    at connectDatabase (/mnt/d/Ecommerce/backend/config/database.js:4:14)
    at Object.<anonymous> (/mnt/d/Ecommerce/backend/server.js:11:1)      
    at Module._compile (internal/modules/cjs/loader.js:1085:14) {        
  reason: TopologyDescription {
    type: 'Unknown',
    servers: Map(1) { '127.0.0.1:27017' => [ServerDescription] },        
    stale: false,
    compatible: true,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    logicalSessionTimeoutMinutes: undefined
  }
}

I have used 'mongod' also.
I have created a folder also in my C:\data\db
used 127.0.0.1 also, instead of localhost

I don't know why this error is still there, after trying so many solution. How can I resolve it?

Upvotes: 2

Views: 6056

Answers (2)

Chukwunazaekpere
Chukwunazaekpere

Reputation: 1012

for linux and mac users, I simply did the following, from my terminal

1) change mongos port number: cd ~
2) sudo nano /etc/mongod.conf
3) locate the line: # network interfaces and change 27017 to 27018
4) save the file: ctrl + x; then shift + y; then press enter
5) restart mongod: sudo systemctl restart mongod
6) check if mongo is trully running: sudo systemctl mongod

Upvotes: -1

Vaibhav Haldia
Vaibhav Haldia

Reputation: 51

I am running this on Windows and my task manager had stopped this service and it was not starting automatically. That's why it was not running.

If you also got the same error just check by:

  1. Type "services" in Windows search bar
  2. Open it and scroll upto the mongoDB service
  3. Start/restart it manually if its stopped.

For the reference

Upvotes: 2

Related Questions