I recently installed mongodb-2.6.0 with Homebrew.
After successfully installed, I tried to connect using the mongo
command. I am receiving the following errors which do not allow 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
If you have already installed MongoDB then first try to run mongod as a sudo user, I was facing the issue because of not running mongod as a superuser.
I have pasted the o/p for both the commands(mongod and sudo mongod) at very bottom, you can check that too but
First try this
not this
I had installed MongoDB on my MAC OS X Sierra 10.12.6 by by running the following command in sequence.
then created a directory to which mongod process will write the data, this is optional as mongod process takes it by default, see this useful guide at https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
Finally started mongod process as follows
Oputput of mongod (failed) and sudo mongod (succeeded) commands on my terminal.
Then I opened new terminal to start querying the MongoDB, it worked.
That's it.
It can happen when the mongodb service is not running on the mac. To start it, I tried
and it worked.
Edit: According to the discussion on this PR on homebrew: https://github.com/Homebrew/homebrew/issues/30628
brew services
is deprecated, I looked around on SO and found these answers now answer the question: What is the correct way to start a mongod service on linux / OS X?In another tab, you can start the mongo shell with
Then return to the previous tab and try again. If you're having trouble setting up your mongoshell, check out this link on the mongo shell: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/ or this link on installing mongodb: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/
My similar error is resolved by deleting "sudo rm /data/db/mongod.lock" file while trying to run mongod. Now u can run mongod and then mongo.
I was having the same issue when calling
mongod
from the command line.I resolved this by calling instead
sudo mongod
.