Human Cyborg Relations
Human Cyborg Relations

Reputation: 1244

Mongodb connection failed (Connection refused)

I'm creating a basic web application on OSX for the first time.

I've installed MongoDB and I can use the 'mongo' command from the terminal, but I can't get into the mongodb shell with it.

SOE-SOE01492:evnt humadshah$ mongo
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27017
2017-07-13T13:29:20.917+0500 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-07-13T13:29:20.917+0500 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

I have absolutely no idea what is causing this. I have never encountered this error on Windows before.

Upvotes: 3

Views: 20730

Answers (2)

Daniel Agus Sidabutar
Daniel Agus Sidabutar

Reputation: 349

I try this code and work for me. Make sure you fully step install mongodb.

$ brew services start mongodb

then check your connection mongodb

$ mongo

The result :

Server has startup warnings: 
2017-10-01T10:54:13.444+0700 I CONTROL  [initandlisten] 
2017-10-01T10:54:13.445+0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-10-01T10:54:13.445+0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-10-01T10:54:13.445+0700 I CONTROL  [initandlisten] 

Upvotes: 10

Memduh
Memduh

Reputation: 866

mongo command is just a client to connect to mongodb. If mongodb process is not running, mongo command fails the connect to mongodb.

Can you try starting mongodb service manually? I do not know how to start it in OSX but in linux it would be;

$ sudo service mongodb start

or

$ sudo systemctl start mongodb

For OSX

$ cd mongo-db-directory
$ ./bin/mongod

Upvotes: 4

Related Questions