Naiim Khaskhoussi
Naiim Khaskhoussi

Reputation: 91

MongoDB Compass connect ECONNREFUSED 127.0.0.1:27017

The default localhost connection refused.

screenshot

Upvotes: 7

Views: 68522

Answers (12)

First you need to start MongoDB server. Open VS code terminal or cmd if you have add mongodb on environment variables, and confirm that you are on C:\user\user directory. Then execute: mongodb/bin/mongod.exe --dbpath=/users/user/mongodb-data where /users/user/mongodb-data is your path to mongodb data that you should have.

After that, the mongodb server is running and you can conected from the MongoDB Compass.

Upvotes: 0

Ali Bonakdar
Ali Bonakdar

Reputation: 41

On Windows, follow the steps below:

  1. Windows button + R
  2. type "services" and press Enter,
  3. Find "MongoDb", right click and select "Start"
  4. Go back to MongoDBCompass, and try again to connect to localhost.

Upvotes: 1

Muhammad Awais Zahid
Muhammad Awais Zahid

Reputation: 31

If you're using windows and getting this error Follow this:

  • Search Services Find Mongodb Server Click on it Click on the
    start It will start local service for you.

Upvotes: 1

Muhammad Hassan
Muhammad Hassan

Reputation: 11

This issue arises due to the following reasons:

  • MongoDB is not installed completely.
  • System env variables do not contain a path for MongoDB.

Solution

  • Reinstall MongoDB and select complete setup to install all the associated packages of MongoDB.

  • Type in the Windows search bar for system environment variables, select environment variables and look for the "Path" in the System Variables list.

  • Click on the path and add a new path for MongoDB by browsing in the system where the MongoDB folder is saved and select the bin folder in the MongoDB directory.

  • Open cmd and type mongod, this will start MongoDB services.

  • Now your Mongo Compass should connect and not throw a refused error.

Upvotes: 1

Dev K
Dev K

Reputation: 61

Seen so much stuff for Windows but on mac I just ran

brew services start mongodb-community

Upvotes: 6

user21946984
user21946984

Reputation: 1

you need to check the status of your localDB ,this command is for ubantu

=>sudo systemctl status mongod

check the status and start your local DB

=>sudo systemctl start mongod

using this command I'm able to connect my local as well as mongo compass.

Upvotes: 0

fan jarvis
fan jarvis

Reputation: 1

you should create a file for saving data;please take attention to the erro infomation in power shell,follow the infomation and you will solve it. add the file ,for example:"D:/data/db"

Upvotes: 0

Mister Q
Mister Q

Reputation: 370

I'm a Mac user and I hit this error while using MongoDb compass, but I solved this by checking IP address in mongod.config (which is located by default on Mac at /opt/homebrew/etc/ if you used homebrew to install it) and launching the server using this config file. To make it sure I set the following config (ip address depending of what you set up in you hosts file too):

net:
  bindIp: 127.0.0.1,0.0.0.0
  port: 27017
  ipv6: false

Then even if I was in the folder which contains the config file, I had to specify the config file in order to start the mongodb service with the following command line:

mongod --config mongod.config

Then I was able to connect through MongoDb Compass.

Hope this help Mac users who are seeking answers and maybe also Windows users because you might also need to specify that config file even if you are the MongoDb Server folder.

Upvotes: 2

chamin madura
chamin madura

Reputation: 21

reinstall mongodb as network service. it works for me.

Upvotes: 2

Bhavya
Bhavya

Reputation: 197

Type services in start. open it. search for mongodb there. start/restart the mongodb from services.

Upvotes: 17

INAGANTI RAVI CHANDRA
INAGANTI RAVI CHANDRA

Reputation: 19

must you need to run MongoDB server on local? for that, you need to:

  • run a command on the command prompt. open command prompt goes to a file location like C:\Program Files\MongoDB\Server\4.4\bin.

  • type mongod and press Enter key.

After a few minutes, mongo will be connected. then add path variable to the environment.

Upvotes: 1

Mayantha Fernando
Mayantha Fernando

Reputation: 61

This message shows that your mongo is disconnected. Therefore you should open your cmd (Windows) Then type `mongod and press Enter key. After a few minutes, mongo will be connected. Then connect through your MongoDB Compass

Upvotes: 3

Related Questions