5

The default localhost connection refused.

  • Operating System: Windows 7
  • MongoDB Compass: Version 1.19.12

screenshot

  • Does it accessible on the terminal/command prompt? if yes then open your mongod.cfg file then check net: bindIp: 127.0.0.1 port: 27017 Use that port to open in your MongoDB editor – Mohammad Zeeshan Dec 17 '19 at 13:27
  • Check if Mongodb is running first of all, I would usually suggest running `sudo service mongod status`, however, I believe this won't work in windows, but I'm sure there's something equivalent in the docs – Lucas Abbade Dec 17 '19 at 13:27
  • Thanks, Mohammad and Lucas, when I update my MongoDB Compass to 1.20.3 version the problem resolved. – Naiim Khaskhoussi Dec 20 '19 at 10:04
  • Seems mongod is not running. Please check once – ROHIT KHURANA Oct 30 '20 at 03:28

9 Answers9

9

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

Bhavya
  • 109
  • 2
  • 6
3

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

2

reinstall mongodb as network service. it works for me.

1

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.

Benzara Tahar
  • 2,058
  • 1
  • 17
  • 21
1

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.

Mister Q
  • 370
  • 6
  • 20
0

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"

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 26 '23 at 22:03
0

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.

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
0

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

brew services start mongodb-community
Dev K
  • 1
0

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.