DEV Community

Balaram
Balaram

Posted on

How to fix "connect ECONNREFUSED 127.0.0.1:27017, connect ECONNREFUSED ::1:27017" in mongo db compass

So you are trying to create a mern project but you get this error message and now you don't know what to do ?
I am here for your rescue.
Image description

There are plenty of method to fix this issue but I will tell you two method in this post

Method 1

Step 1: Check if mongo is properly installed in your pc by typing following in your terminal

mongod –version`

Step 2: If it is not installed then go ahead and install it from this link Download .

Step 3: Even after installing it is not working then press window key + R and type services.msc

Step 4: Find the mongo and the restart that

This step will fix your problem

Method 2

Instead of installing mongo db if you alread have docker then u can use docker for this purpose

Step 1: In your code create dockercompose.yml file

Step 2: Paste the following code .

version: "3"
services:
mongo:
image: mongo
expose:
- 27017
ports:
- "27017:27017"

Breakdown of code
a.Version means the specific version of docker
b.Services means containers that should run together in same environment in this cose it is only mongo
c.Image: Specifies the Docker image to use for this container.Here, it's set to mongo, which means Docker will pull the official MongoDB image from Docker Hub if it's not already present locally.
d.Expose and port make it accessible outside docker container

Step 3: Boom thats it you now have working mongodb compass

Top comments (0)