Gigi101
Gigi101

Reputation: 191

connect ECONNREFUSED 127.0.0.1:27017 in Mongodb Compass

I restarted my computer to try to update it, and before restarting, I was also working on another project. Now, my project with a node.js backend is giving me this error:

reason: TopologyDescription {
    type: 'Single',
    setName: null,
    maxSetVersion: null,
    maxElectionId: null,
    servers: Map(1) {
      'localhost:27017' => ServerDescription {
        address: 'localhost:27017',
        error: Error: connect ECONNREFUSED 127.0.0.1:27017
            at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1132:16) {
          name: 'MongoNetworkError'
        },
        roundTripTime: -1,
        lastUpdateTime: 58154302,
        lastWriteDate: null,
        opTime: null,
        type: 'Unknown',
        topologyVersion: undefined,
        minWireVersion: 0,
        maxWireVersion: 0,
        hosts: [],
        passives: [],
        arbiters: [],
        tags: []
      }
    },
    stale: false,
    compatible: true,
    compatibilityError: null,
    logicalSessionTimeoutMinutes: null,
    heartbeatFrequencyMS: 10000,
    localThresholdMS: 15,
    commonWireVersion: null
  }

and my mongodb compass is giving me: connect ECONNREFUSED 127.0.0.1:27017. My operating system is macOS Big Sur.

In another post someone suggested restarting the mongod process and connecting again. I tried following those instructions mac-mongodb, but when I go to 'From a new terminal, issue the following: mongosh' my terminal gave me command not found: mongosh. I also tried testing it with PATH="/usr/local/opt/mongodb-community@4.4/bin" mongo MongoDB shell version v4.4.13 and I still got Error: couldn't connect to server 127.0.0.1:27017, with connection refused.

Does anyone know how to fix this? I would really appreciate any help or advice. Thank you!

Upvotes: 0

Views: 14459

Answers (3)

bharatadk
bharatadk

Reputation: 639

Delete socket file

sudo rm -rf /tmp/mongodb-27017.sock

Restart mongodb service

sudo service mongod restart
mongosh

Upvotes: 3

deezyto
deezyto

Reputation: 29

Restarting mongodb helped me:

brew services stop mongodb-community@5.0
brew services start mongodb-community@5.0

Upvotes: 1

Abishethvarman V
Abishethvarman V

Reputation: 127

It may be happened due to the mongoDB server stopped. To resolve this, go to task manager. In the top bar, click Services. Search mongoDB in the set up files. If the status is "Stopped". Give a right click and start running the server. It will work again. For confirming this action, open the cmd and type mongosh and youll be getting the connection result.

Upvotes: 0

Related Questions