• Register
search
Log In
0 votes
1.1k views

Problem :

I am new to Mongodb and I have recently installed mongodb-2.6.0 with Homebrew. After successful installation, I just tried to connect using the mongo command but I am receiving the below errors which are not allowing me to connect:

Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused

 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146

 exception: connect failed

7.5k points

2 Answers

0 votes

Solution :

I was involved in full stack Django development and while developing an application using Mongodb as database backend, I also encountered below error after installing Mongodb on my mac. so first, I installed Mongodb by using brew install command as follows:

brew update

brew install mongodb

After installing the Mongodb on my Mac, I tried to just access the mongo shell by using mongo command, but I got following error "Cannot connect to mongodb errno:61 Connection refused error" . Following is the full trace:

MongoDB shell version: 2.6.6

connecting to: test

warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused

Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146

exception: connect failed

So after receiving the error I searched for correct ways to start Mongodb on Mac OS. I tried many ways but the one which worked for me is as below:

In your shell write sudo mongod to start it as below:

$ mkdir -p /data/db

$ sudo mongod

This helped me in starting my Mongodb. Next I simply opened another shell instance and wrote the required mongo command and it worked without giving error Error Cannot connect to mongodb errno:61 Connection refused!

So my MongoDB starting Problem Solved.

36.1k points
0 votes

This error can happen when the MongoDB service is not running on the mac while you involved in full-stack Django development and developing an application using MongoDB as the database backend. When the user tries to access the mongo shell by using the mongo command but got an error;

“Cannot connect to MongoDB error:61 connection refused.”

 This error can be solved in many ways;

Solution 1:

To solve your issue, you have to follow the instructions which are given to you by brew after your “brew install MongoDB”.

To launched start the MongoDB at login;

ln –sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

Then load the MongoDB again by using the command;

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

If you don’t need to launchtl, you can just run the following command;

mongod –config /usr/local/etc/mongod.conf

Solution 2:

Install the MongoDB by using the brew install command, if you already have MongoDB then you don’t need to follow this step;

brew update

brew install mongodb

Run the MongoDB Daemon by using the command;

mkdir –p /data/db

sudo mongod

Now run the mongo shell interface by using the command;

mogo

In this sequence, you can be able to run the mongo command without any error.

 

3.9k points

Related questions

2 votes
1 answer 55 views
55 views
Problem : I am very new to Mongodb, I am facing below error if I try to run the Mongodb. I had installed it with the help of Homebrew. Stewarts-MacBook-Pro:~ stewart$ mongod 2020-05-05T15:31:15.911+0700 I CONTROL  [initandlisten] MongoDB starting : pid ... +0700 I CONTROL  [initandlisten] shutting down with code:48 Stewarts -MacBook-Pro:~ stewart $ Kindly help me in resolving above Mongodb error.
asked May 6 stewart 4k points
1 vote
1 answer 16 views
16 views
Problem : Recently I have started learning Homebrew. Now if I try to run Homebrews brew doctor command on my Mac OS X 10.9.2 I have started receiving the below listed warning message: Warning: Python is installed at /Library/Frameworks/Python.framework Homebrew only ... /usr/local/bin/python. But still if I rerun the brew doctor command I am still facing the same warning message listed above.
asked Apr 4 morrisBson 3.2k points
0 votes
1 answer 176 views
176 views
Problem : Currently I am learning Homebrew (Mojave). Recently I tried to install the node using Homebrew (Mojave) but after sometime my Php stopped working and now if I try to run the command php -v I face below error: php -v dyld: Library not loaded: /usr/local ... from: /usr/local/bin/php Reason: image not found I have also tried to uninstall my both node and icu4c but my problem still persists
asked Feb 20 mphil 2.3k points
0 votes
2 answers 153 views
153 views
Problem : In the MacOS Mojave terminal I am trying to install a python package with pip. At the end of it says as follows : You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Here ... to do.Also I just realized that it says Python 2.7 in the error message but I have python 3 and want to use only python 3.
asked Dec 10, 2019 alecxe 7.5k points
0 votes
1 answer 424 views
424 views
Problem : I am very new to Curl. I have recently started learning Curl. Whenever I try to connect to the Elasticsearch using below command curl http://localhost:9200 it is working properly. But when I try to run the following command curl http://IpAddress: ... showing me below error “Curl: (7) failed to connect to localhost port 9200: connection refused” How can I resolve above error?
asked Feb 20 mphil 2.3k points